(b *testing.B)
| 50 | } |
| 51 | |
| 52 | func BenchmarkStringOperationsNoMatch(b *testing.B) { |
| 53 | for _, tc := range []struct { |
| 54 | name, pattern, input string |
| 55 | options RegexOptions |
| 56 | }{ |
| 57 | {"Anchored", `^func\b`, strings.Repeat("x := someIdentifier + 42 // comment\n", 100), None}, |
| 58 | {"RejectedCandidate", `func\b`, "funcx" + strings.Repeat("x", 3400), None}, |
| 59 | {"RightToLeft", `func\b`, strings.Repeat("x", 3400), RightToLeft}, |
| 60 | } { |
| 61 | for _, api := range []struct { |
| 62 | name string |
| 63 | call func(*Regexp, string) error |
| 64 | }{ |
| 65 | {"FindStringMatch", func(re *Regexp, input string) error { |
| 66 | _, err := re.FindStringMatch(input) |
| 67 | return err |
| 68 | }}, |
| 69 | {"Replace", func(re *Regexp, input string) error { |
| 70 | _, err := re.Replace(input, "replacement", -1, -1) |
| 71 | return err |
| 72 | }}, |
| 73 | {"ReplaceFunc", func(re *Regexp, input string) error { |
| 74 | _, err := re.ReplaceFunc(input, func(Match) string { return "replacement" }, -1, -1) |
| 75 | return err |
| 76 | }}, |
| 77 | {"Split", func(re *Regexp, input string) error { |
| 78 | _, err := re.Split(input, -1) |
| 79 | return err |
| 80 | }}, |
| 81 | {"FindAllStringIndex", func(re *Regexp, input string) error { |
| 82 | _, err := re.FindAllStringIndex(input, 100) |
| 83 | return err |
| 84 | }}, |
| 85 | } { |
| 86 | b.Run(api.name+"/"+tc.name, func(b *testing.B) { |
| 87 | re := MustCompile(tc.pattern, tc.options) |
| 88 | b.ReportAllocs() |
| 89 | b.ResetTimer() |
| 90 | for i := 0; i < b.N; i++ { |
| 91 | if err := api.call(re, tc.input); err != nil { |
| 92 | b.Fatal(err) |
| 93 | } |
| 94 | } |
| 95 | }) |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func BenchmarkFindAllRunesIndexNoMatch(b *testing.B) { |
| 101 | re := MustCompile(`^func\b`) |
nothing calls this directly
no test coverage detected