Skip to content

re.MatchString Benchmark cost too much time #137

@tjbrains

Description

@tjbrains

the benchmark cost 116.923s to finish, there is maybe a issue here:

func BenchmarkMatchStringCache_WithoutCache_coregex(b *testing.B) {
	runtime.GOMAXPROCS(4)

	var data = strings.Repeat("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36", 8)
	var re = coregex.MustCompile(`(?iU)\b(eval|system|exec|execute|passthru|shell_exec|phpinfo)\b`)

	b.ReportAllocs()
	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_ = re.MatchString(data)
		}
	})
}

result:

goos: darwin
goarch: arm64
pkg: [MY REPOSITORY]/internal/waf/utils
cpu: Apple M2 Max
BenchmarkMatchStringCache_WithoutCache_coregex-12            100        1148587620 ns/op        1737521223 B/op     1445 allocs/op
testing: BenchmarkMatchStringCache_WithoutCache_coregex-12 left GOMAXPROCS set to 4
PASS
ok      github.com/[MY REPOSITORY]/internal/waf/utils        116.923s

Metadata

Metadata

Assignees

Labels

arch: arm64ARM64 specific (NEON, future)area: dfaLazy DFA, OnePass DFAarea: literalLiteral extraction from ASTarea: metaStrategy selection, engine orchestrationbench: vs-stdlibComparison with Go stdlib regexpeffort: 8Very large, ~1 weekplatform: macosmacOS-specificpriority: criticalRelease blocker, correctness regressionstatus: confirmedVerified, ready for workstrategy: teddyTeddy SIMD multi-pattern prefiltertype: performanceSpeed/memory improvement or regression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions