Skip to content

Commit

Permalink
update benchmark paralelism
Browse files Browse the repository at this point in the history
  • Loading branch information
jptosso committed Nov 8, 2024
1 parent dce8d8a commit b67ffc1
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions internal/corazawaf/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b67ffc1

Please sign in to comment.