mirror of
https://github.com/golang/go.git
synced 2026-04-02 17:30:01 +09:00
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:
@@ -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+")
|
||||
|
||||
Reference in New Issue
Block a user