Comments (4)
Added new candidate, https://github.com/AspieSoft/go-regex.
from teler-waf.
Current results
goos: linux
goarch: amd64
pkg: benchmark-regexp
cpu: 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
GOMAXPROCS: 16
Click to toggle contents of bench code
package main
import (
"fmt"
"regexp"
"testing"
aspiesoft_regex "github.com/AspieSoft/go-regex/v8"
grbit_pcre "github.com/GRbit/go-pcre"
scorpionknifes_pcre "github.com/scorpionknifes/go-pcre"
)
const (
patternNonPCRE = `(?i)(?:on(?:webkitanimationiteration|(?:(?:webkitanimation|(?:select|drag))s|t(?:ransition|ouch)s)tart|(?:webkit(?:transi|anima)tione|t(?:ransition|ouch)e|scrolle)nd|(?:beforescriptexecut|afterscriptexecut|(?:p(?:ointerrawupda|(?:opsta|as))|timeupda)t|b(?:eforetoggl|ounc)|(?:pointer|drag)leav|(?:pointer|touch)mov|mouse(?:lea|mo)v|pa(?:gehid|us)|resiz|clos)e|(?:mozfullscreen|fullscreen|(?:selec|dura)tion|hash|cue)change|unhandledrejection|a(?:nimation(?:iteration|cancel|start|end)|fterprint|uxclick)|transitioncancel|toggle\(popover\)|loaded(?:meta)?data|(?:canplaythroug|searc)h|(?:transitionru|(?:pointer|key)dow|mousedow|(?:focus|beg)i)n|pointerenter|(?:beforeunloa|invali|(?:seek|end)e|unloa)d|volumechange|c(?:(?:ontextmenu|ut)|opy)|(?:pointerov|drag(?:ent|ov))er|(?:(?:beforeinp|focuso)u|beforeprin|pointerou|beforecu|mouseou|submi|re(?:pea|se)|inpu)t|beforecopy|mouse(?:enter|over|up)|(?:mouse)?wheel|ratechange|(?:pointeru|keyu|dro)p|pageshow|progress|keypress|dblclick|canplay|dragend|playing|s(?:eeking|how)|message|s(?:croll|elect)|toggle|finish|change|focus|(?:erro|blu)r|click|start|drag|load|play|end))\s*?=`
patternPCRE = `(?:\/\w*\s*\)\s*\()|(?:\([\w\s]+\([\w\s]+\)[\w\s]+\))|(?:(?<!(?:mozilla\/\d\.\d\s))\([^)[]+\[[^\]]+\][^)]*\))|(?:[^\s!][{([][^({[]+[{([][^}\])]+[}\])][\s+",\d]*[}\])])|(?:"\)?\]\W*\[)|(?:=\s*[^\s:;]+\s*[{([][^}\])]+[}\])];)`
)
func BenchmarkCompileNonPCRE(b *testing.B) {
var err error
b.ResetTimer()
b.Run("regexp", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = regexp.Compile(patternNonPCRE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
b.ResetTimer()
b.Run("AspieSoft/go-regex", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = aspiesoft_regex.CompTry(patternNonPCRE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
b.ResetTimer()
b.Run("GRbit/go-pcre", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = grbit_pcre.Compile(patternNonPCRE, grbit_pcre.MULTILINE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
b.ResetTimer()
b.Run("scorpionknifes/go-pcre", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = scorpionknifes_pcre.Compile(patternNonPCRE, scorpionknifes_pcre.MULTILINE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
}
func BenchmarkCompilePCRE(b *testing.B) {
var err error
b.ResetTimer()
b.Run("AspieSoft/go-regex", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = aspiesoft_regex.CompTry(patternPCRE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
b.ResetTimer()
b.Run("GRbit/go-pcre", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = grbit_pcre.Compile(patternPCRE, grbit_pcre.MULTILINE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
b.ResetTimer()
b.Run("scorpionknifes/go-pcre", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err = scorpionknifes_pcre.Compile(patternPCRE, scorpionknifes_pcre.MULTILINE)
if err != nil {
panic(err)
}
}
})
fmt.Println(b.Elapsed())
}
BenchmarkCompileNonPCRE
Engine | ns/op | B/op | allocs/op | elapsed |
---|---|---|---|---|
regexp | 127972 | 131641 | 690 | 1.323665572s |
AspieSoft/go-regex | 29328 | 2322 | 3 | 1.384703177s |
GRbit/go-pcre | 21163 | 2744 | 6 | 1.330075384s |
scorpionknifes/go-pcre | 20630 | 12 | 2 | 1.735374764s |
BenchmarkCompilePCRE
Engine | ns/op | B/op | allocs/op | elapsed |
---|---|---|---|---|
AspieSoft/go-regex | 6647 | 465 | 3 | 1.122028641s |
GRbit/go-pcre | 4444 | 824 | 6 | 2.195591583s |
scorpionknifes/go-pcre | 4250 | 12 | 2 | 1.267168176s |
from teler-waf.
Reopening as per #90 (comment).
from teler-waf.
I will mark this issue as completed, because - upon evaluating the trade-offs associated with migrating the built-in regexp
engine within CustomRule
and the inThreatRegexp
utility (used by BadIPAddress
and DirectoryBruteforce
), there is no performance enhancements were observed.
from teler-waf.
Related Issues (20)
- [feature] load custom rules from path
- [feature] Load options from file
- [feature] Kong plugin integration
- [feature] Caddy module/plugin integration HOT 1
- [bug] improper client IP is captured in getClientIP util func HOT 1
- [bug] nil pointer dereference in checkBadReferrer method
- [proposal] deprecating `Excludes` with `Whitelists`
- [proposal] deprecating `Excludes` with `Whitelists`
- [docs] benchmarking
- [docs] teler-waf v1.1.7 comparison
- [feature] more log output option HOT 4
- [bug] race condition on checkFalcoEvents
- [proposal] Redesign Custom Response Configuration
- pliss help me HOT 1
- [feature] Verify datasets with checksum
- [feature] Caching any DSL expressions
- [feature] Copy downloaded teler-resources into temp dir for fallback on threat.Get
- [proposal] Remove `dsl` package
- support websocket HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teler-waf.