Skip to content

Commit 174a428

Browse files
committed
Add Parser benchmarks
1 parent 652ba01 commit 174a428

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/filter/parser_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,30 @@ func FuzzParser(f *testing.F) {
492492
}
493493
})
494494
}
495+
496+
func BenchmarkParser(b *testing.B) {
497+
expr := "foo=bar&bar!=foo&column=value"
498+
// Add more complexity to the expression by nesting conditions
499+
for i := 0; i < 100; i++ {
500+
switch i % 4 {
501+
case 0:
502+
expr = "(" + expr + "&col" + string(rune('A'+(i%26))) + "=val" + string(rune('a'+(i%26))) + ")"
503+
case 1:
504+
expr = "!(" + expr + "|col" + string(rune('A'+(i%26))) + "!=val" + string(rune('a'+(i%26))) + ")"
505+
case 2:
506+
expr = "(" + expr + "|col" + string(rune('A'+(i%26))) + ">=val" + string(rune('a'+(i%26))) + ")"
507+
case 3:
508+
expr = "!(" + expr + "&col" + string(rune('A'+(i%26))) + "<=val" + string(rune('a'+(i%26))) + ")"
509+
}
510+
}
511+
expr += "&" + strings.Repeat("x~y*|", 50) + "z~*w*|!((foo=bar|baz!=qux)&(!(alpha=beta)|gamma<=delta))"
512+
b.Logf("Benchmarking filter expression: %s", expr)
513+
514+
b.ReportAllocs() // Report allocations statistics
515+
516+
for b.Loop() {
517+
if _, err := Parse(expr); err != nil {
518+
b.Fatalf("Failed to parse filter expression: %s", err)
519+
}
520+
}
521+
}

0 commit comments

Comments
 (0)