-
Notifications
You must be signed in to change notification settings - Fork 38
Regexp Utils #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Regexp Utils #652
Conversation
afaik, using the combination of tip: i actually built a package called
package benchmark_test
import (
"testing"
AspieSoft "github.com/AspieSoft/go-regex/v8"
GRbit "github.com/GRbit/go-pcre"
dlclark "github.com/dlclark/regexp2"
scorpionknifes "github.com/scorpionknifes/go-pcre"
wasilibs "github.com/wasilibs/go-re2"
"github.com/dwisiswant0/pcregexp"
)
func BenchmarkMatch(b *testing.B) {
tests := []struct {
name string
pattern string
text []byte
}{
{"simple", `p([a-z]+)ch`, []byte("peach punch pinch")},
{"email", `\b\w+@\w+\.\w+\b`, []byte("[email protected]")},
{"backreference", `(\w+)\s+\1`, []byte("hello hello world")},
{"lookaround", `(?<=foo)bar`, []byte("foobar")},
}
for _, tt := range tests {
r1 := pcregexp.MustCompile(tt.pattern)
b.ResetTimer()
b.Run("pcregexp/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r1.Match(tt.text)
}
})
r2 := dlclark.MustCompile(tt.pattern, 0)
b.ResetTimer()
b.Run("dlclark-regexp2/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r2.MatchString(string(tt.text))
}
})
r3, err := AspieSoft.CompTry(tt.pattern)
if err != nil {
b.Fatalf("r3: failed to compile pattern: %v", err)
}
b.ResetTimer()
b.Run("AspieSoft-regex/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r3.Match(tt.text)
}
})
r4, err := scorpionknifes.Compile(tt.pattern, 0)
if err != nil {
b.Fatalf("r4: failed to compile pattern: %v", err)
}
r4Matcher := r4.NewMatcher()
b.ResetTimer()
b.Run("scorpionknifes-pcre/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r4Matcher.Match(tt.text, 0)
}
})
r5, err := GRbit.Compile(tt.pattern, 0)
if err != nil {
b.Fatalf("r5: failed to compile pattern: %v", err)
}
b.ResetTimer()
b.Run("GRbit-pcre/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r5.MatchWFlags(tt.text, 0)
}
})
r6, err := wasilibs.Compile(tt.pattern)
if err != nil {
b.Skipf("r6: failed to compile pattern: %v", err)
}
b.ResetTimer()
b.Run("wasilibs-re2/"+tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
r6.MatchString(string(tt.text))
}
})
}
} latest benchstat of |
Used in projectdiscovery/wappalyzergo#135