MCPcopy Create free account
hub / github.com/dlclark/regexp2 / BenchmarkFindStringMatchMixed

Function BenchmarkFindStringMatchMixed

string_processing_benchmark_test.go:8–29  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

6)
7
8func BenchmarkFindStringMatchMixed(b *testing.B) {
9 for _, tc := range []struct{ name, pattern string }{
10 {"Literal", `^a+$`},
11 {"RepeatedCapture", `^(a)+$`},
12 } {
13 b.Run(tc.name, func(b *testing.B) {
14 re := MustCompile(tc.pattern)
15 hit := strings.Repeat("a", 256)
16 miss := hit[:len(hit)-1] + "b"
17 b.ReportAllocs()
18 // Each iteration measures a miss followed by a hit on the same regexp.
19 for b.Loop() {
20 if m, err := re.FindStringMatch(miss); m != nil || err != nil {
21 b.Fatal(m, err)
22 }
23 if m, err := re.FindStringMatch(hit); m == nil || err != nil {
24 b.Fatal(m, err)
25 }
26 }
27 })
28 }
29}
30
31func BenchmarkFindNextMatch(b *testing.B) {
32 for _, tc := range []struct{ name, pattern string }{

Callers

nothing calls this directly

Calls 2

FindStringMatchMethod · 0.80
MustCompileFunction · 0.70

Tested by

no test coverage detected