¯\_(ツ)_/¯

main
pxi 2023-12-31 18:18:29 +01:00
parent a613b8331f
commit 1352e285bb
5 changed files with 40 additions and 11 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strconv"
"os"
"internal/corpus"
)
@ -16,10 +17,16 @@ func main() {
defer f.Close()
lines := corpus.MakeCorpus()
var total int = 1000
if len(os.Args) > 1 {
i, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatal(err)
}
total = i
}
// Write to file
for _, line := range lines {
f.WriteString(line + "\n")
}
corpus := corpus.MakeCorpus(total)
f.WriteString(corpus)
}

View File

@ -16,7 +16,16 @@ func main() {
defer f.Close()
lines := pairs.MakePairs()
var total int = 1000
if len(os.Args) > 1 {
i, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatal(err)
}
total = i
}
lines := pairs.MakePairs(total)
// Write to file
for _, line := range lines {

View File

@ -3,13 +3,14 @@ package corpus
import (
"fmt"
"math/rand"
"strings"
)
func MakeCorpus() []string {
func MakeCorpus(n int) string {
// Generate data
lineLength := 100
var lines []string
for i := 1; i <= 1000; i++ {
for i := 1; i <= n; i++ {
lines = append(lines, makeLine(i, lineLength))
}
@ -19,7 +20,7 @@ func MakeCorpus() []string {
lines[i], lines[j] = lines[j], lines[i]
}
return lines
return strings.Join(lines, "\n")
}
func makeLine(line int, lineLength int) string {

View File

@ -5,9 +5,9 @@ import (
"math/rand"
)
func MakePairs() []string {
func MakePairs(n int) []string {
var pairs []string
for i := 1; i <= 1000; i++ {
for i := 1; i <= n; i++ {
pairs = append(pairs, makeKey(i) + "," + makeValue())
}

View File

@ -2,6 +2,8 @@ package replace
import (
"testing"
"internal/corpus"
"internal/pairs"
"internal/replace"
)
@ -16,3 +18,13 @@ func TestBoyerMooreReplace(t *testing.T) {
t.Error("Replacement was wrong.")
}
}
func BenchmarkBoyerMooreReplace(b *testing.B) {
var amount int = 1000
var corpus string = corpus.MakeCorpus(amount)
var pairs []string = pairs.MakePairs(amount)
for n := 0; n < b.N; n++ {
replace.BoyerMooreReplace(corpus, pairs)
}
}