Skip to content

Commit

Permalink
Add benchmark on random inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
psadac committed Dec 22, 2024
1 parent 5f5ed53 commit eb2b813
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions levenshtein_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ func BenchmarkAll(b *testing.B) {
sink = tmp
}

// BenchmarkRandom benchmarks random inputs, of random lengths.
func BenchmarkRandom(b *testing.B) {
const (
nbParams = 10000 // number of random parameters.
maxLen = 100 // maximum length in runes of rune array ra.
maxChanges = 90 // maximum number of changes from rune array ra to rune array rb.
)

rnd := rand.New(rand.NewSource(rndSeed))

// create an array of random inputs.
type param struct{ a, b string }

params := make([]param, 0, nbParams)

for i := 0; i < nbParams; i++ {
ra := RandRunes(rnd, maxLen)
rb := RandRunesChange(rnd, ra, maxChanges)
p := param{a: string(ra), b: string(rb)}
params = append(params, p)
}

b.ReportAllocs()
b.ResetTimer()

for n := 0; n < b.N; n++ {
p := params[n%nbParams]
sink = agnivade.ComputeDistance(p.a, p.b)
}
}

// Fuzzing
// ----------------------------------------------

Expand Down

0 comments on commit eb2b813

Please sign in to comment.