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

Function BenchmarkStringOperationsNoMatch

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

Source from the content-addressed store, hash-verified

50}
51
52func 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
100func BenchmarkFindAllRunesIndexNoMatch(b *testing.B) {
101 re := MustCompile(`^func\b`)

Callers

nothing calls this directly

Calls 6

FindStringMatchMethod · 0.80
ReplaceMethod · 0.80
ReplaceFuncMethod · 0.80
SplitMethod · 0.80
MustCompileFunction · 0.70
FindAllStringIndexMethod · 0.65

Tested by

no test coverage detected