MCPcopy Create free account
hub / github.com/cel-expr/cel-go / BenchmarkBlockEval

Function BenchmarkBlockEval

ext/bindings_test.go:532–566  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

530}
531
532func BenchmarkBlockEval(b *testing.B) {
533 fac := ast.NewExprFactory()
534 expr := fac.NewCall(
535 1, "cel.@block",
536 fac.NewList(2, []ast.Expr{
537 fac.NewIdent(3, "x"),
538 fac.NewIdent(4, "@index0"),
539 fac.NewIdent(5, "@index1"),
540 }, []int32{}),
541 fac.NewCall(9, operators.Add,
542 fac.NewCall(6, operators.Add,
543 fac.NewIdent(7, "@index2"),
544 fac.NewIdent(8, "@index1")),
545 fac.NewIdent(10, "@index0"),
546 ),
547 )
548 blockAST := ast.NewAST(expr, nil)
549 env, err := cel.NewEnv(
550 Bindings(),
551 cel.Variable("x", cel.StringType),
552 )
553 if err != nil {
554 b.Fatalf("cel.NewEnv(Bindings()) failed: %v", err)
555 }
556 prg, err := env.PlanProgram(blockAST, cel.EvalOptions(cel.OptOptimize))
557 if err != nil {
558 b.Fatalf("PlanProgram() failed: %v", err)
559 }
560 input := map[string]any{"x": "hello"}
561 b.ResetTimer()
562 b.ReportAllocs()
563 for i := 0; i < b.N; i++ {
564 prg.Eval(input)
565 }
566}
567
568func TestValidateBindNestingLimit(t *testing.T) {
569 env, err := cel.NewEnv(

Callers

nothing calls this directly

Calls 11

NewCallMethod · 0.95
NewListMethod · 0.95
NewIdentMethod · 0.95
PlanProgramMethod · 0.95
NewExprFactoryFunction · 0.92
NewASTFunction · 0.92
NewEnvFunction · 0.92
VariableFunction · 0.92
EvalOptionsFunction · 0.92
BindingsFunction · 0.85
EvalMethod · 0.65

Tested by

no test coverage detected