Skip to content

Commit

Permalink
add BenchmarkFold
Browse files Browse the repository at this point in the history
With some simple subbenchmarks.
This isn't a particularly varied test,
as all the target strings are identical,
but it's enough to get some basic coverage.
  • Loading branch information
josharian committed May 4, 2023
1 parent 24e57ae commit 19020b4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions fuzzy/fuzzy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ Rhine; and look toward the north and the rising sun. Aquitania extends from the
the Pyrenaean mountains and to that part of the ocean which is near Spain: it looks between the
setting of the sun, and the north star.`

var fuzzyTests = []struct {
type fuzzyTest struct {
source string
target string
wanted bool
rank int
}{
}

var fuzzyTests = []fuzzyTest{
{"zazz", deBelloGallico + " zazz", true, 1544},
{"zazz", "zazz " + deBelloGallico, true, 1544},
{"twl", "cartwheel", true, 6},
Expand Down Expand Up @@ -351,6 +353,24 @@ func BenchmarkMatchFoldBigEarly(b *testing.B) {
}
}

func BenchmarkFindFold(b *testing.B) {
b.Run("Plain", func(b *testing.B) { benchmarkFindFold(b, fuzzyTests[2]) })
b.Run("BigLate", func(b *testing.B) { benchmarkFindFold(b, fuzzyTests[0]) })
b.Run("BigEarly", func(b *testing.B) { benchmarkFindFold(b, fuzzyTests[1]) })
}

func benchmarkFindFold(b *testing.B, ft fuzzyTest) {
src := ft.source
var tgts []string
for i := 0; i < 128; i++ {
tgts = append(tgts, ft.target)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
FindFold(src, tgts)
}
}

func BenchmarkRankMatch(b *testing.B) {
ft := fuzzyTests[2]
for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit 19020b4

Please sign in to comment.