Skip to content

Commit 57ecc15

Browse files
committed
tests: adds mage target for CRS benchmarks.
1 parent bb55b68 commit 57ecc15

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

magefile.go

+12
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,15 @@ func Precommit() error {
223223
func Check() {
224224
mg.SerialDeps(Lint, Test)
225225
}
226+
227+
func CRSBenchmark() error {
228+
bench := "BenchmarkCRSRuntime(Simple|Large)(GET|POST)"
229+
err := sh.RunV("go", "test", "-run=^$,", "-benchmem", "-bench=^"+bench+"$", "./testing/coreruleset", "-cpuprofile=cpuprof.out")
230+
if err != nil {
231+
return err
232+
}
233+
234+
fmt.Println("\nTo analyze the benchmark results, run:\n")
235+
fmt.Println("$ go tool pprof -http=:8080 cpuprof.out\n")
236+
return nil
237+
}

testing/coreruleset/coreruleset_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func BenchmarkCRSCompilation(b *testing.B) {
5353
}
5454
}
5555

56-
func BenchmarkCRSSimpleGET(b *testing.B) {
56+
func BenchmarkCRSRuntimeSimpleGET(b *testing.B) {
5757
waf := crsWAF(b)
5858

5959
b.ResetTimer() // only benchmark execution, not compilation
@@ -80,7 +80,7 @@ func BenchmarkCRSSimpleGET(b *testing.B) {
8080
}
8181
}
8282

83-
func BenchmarkCRSSimplePOST(b *testing.B) {
83+
func BenchmarkCRSRuntimeSimplePOST(b *testing.B) {
8484
waf := crsWAF(b)
8585

8686
b.ReportAllocs()
@@ -112,7 +112,7 @@ func BenchmarkCRSSimplePOST(b *testing.B) {
112112
}
113113
}
114114

115-
func BenchmarkCRSLargePOST(b *testing.B) {
115+
func BenchmarkCRSRuntimeLargePOST(b *testing.B) {
116116
waf := crsWAF(b)
117117

118118
postPayload := []byte(fmt.Sprintf("parameters2=and&other2=%s", strings.Repeat("a", 10000)))

0 commit comments

Comments
 (0)