From 19020b441f1a7b17675764d3ac9daf0ade8601b4 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 4 May 2023 15:23:45 -0700 Subject: [PATCH] add BenchmarkFold 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. --- fuzzy/fuzzy_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/fuzzy/fuzzy_test.go b/fuzzy/fuzzy_test.go index ffecfed..8e6b356 100644 --- a/fuzzy/fuzzy_test.go +++ b/fuzzy/fuzzy_test.go @@ -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}, @@ -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++ {