File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments