From b67ffc19ff60713057f009be2b3d0dd69d8555f2 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosso Date: Fri, 8 Nov 2024 12:30:49 +0000 Subject: [PATCH] update benchmark paralelism --- internal/corazawaf/rule_test.go | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/internal/corazawaf/rule_test.go b/internal/corazawaf/rule_test.go index 739222a62..01e1fb4ad 100644 --- a/internal/corazawaf/rule_test.go +++ b/internal/corazawaf/rule_test.go @@ -385,31 +385,37 @@ func TestAddTransformation(t *testing.T) { } func BenchmarkAddTransformationUnique(b *testing.B) { - rule := NewRule() transformation := func(input string) (string, bool, error) { return "Test", true, nil } - for i := 0; i < b.N; i++ { - transformationName := "transformation" + strconv.Itoa(i) - err := rule.AddTransformation(transformationName, transformation) - if err != nil { - b.Fatalf("Failed to add a transformation: %s", err.Error()) + b.ResetTimer() + b.RunParallel(func(p *testing.PB) { + rule := NewRule() + for p.Next() { + transformationName := "transformation" + b.Name() + err := rule.AddTransformation(transformationName, transformation) + if err != nil { + b.Fatalf("Failed to add a transformation: %s", err.Error()) + } } - } + }) } func BenchmarkAddTransformationSame(b *testing.B) { transformation := func(input string) (string, bool, error) { return "Test", true, nil } - for i := 0; i < b.N; i++ { - rule := NewRule() - transformationName := "transformation" + strconv.Itoa(i) - err := rule.AddTransformation(transformationName, transformation) - if err != nil { - b.Fatalf("Failed to add a transformation: %s", err.Error()) + b.ResetTimer() + b.RunParallel(func(p *testing.PB) { + for p.Next() { + rule := NewRule() + transformationName := "transformation" + err := rule.AddTransformation(transformationName, transformation) + if err != nil { + b.Fatalf("Failed to add a transformation: %s", err.Error()) + } } - } + }) } func TestAddTransformationEmpty(t *testing.T) {