(b *testing.B)
| 6 | ) |
| 7 | |
| 8 | func 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 | |
| 31 | func BenchmarkFindNextMatch(b *testing.B) { |
| 32 | for _, tc := range []struct{ name, pattern string }{ |
nothing calls this directly
no test coverage detected