From b4ef60b9cb74c24108ad02cc11531c0f144bb77d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 6 Feb 2026 12:20:42 -0500 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI --- src/regexp/all_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/regexp/all_test.go b/src/regexp/all_test.go index ead184d286..bc3278db9d 100644 --- a/src/regexp/all_test.go +++ b/src/regexp/all_test.go @@ -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+")