regexp: add BenchmarkFindAllTenMatches

Add a benchmark of FindAll that has matches, to complement BenchmarkFindAllNoMatches.

Change-Id: Ie910bf4913693409fde089ce6df27b13e33f2caf
Reviewed-on: https://go-review.googlesource.com/c/go/+/742800
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Russ Cox
2026-02-06 12:20:42 -05:00
parent 20d78eca0a
commit b4ef60b9cb

View File

@@ -5,6 +5,7 @@
package regexp
import (
"bytes"
"reflect"
"regexp/syntax"
"slices"
@@ -613,6 +614,19 @@ func BenchmarkFindAllNoMatches(b *testing.B) {
}
}
func BenchmarkFindAllTenMatches(b *testing.B) {
re := MustCompile("a+b+")
s := bytes.Repeat([]byte("acddeeabbax"), 10)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
all := re.FindAll(s, -1)
if len(all) != 10 {
b.Fatalf("FindAll(%q) = %q; want 10 matches", s, all)
}
}
}
func BenchmarkFindString(b *testing.B) {
b.StopTimer()
re := MustCompile("a+b+")