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

Function BenchmarkBlockEval

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

Source from the content-addressed store, hash-verified

926}
927
928func BenchmarkBlockEval(b *testing.B) {
929 fac := ast.NewExprFactory()
930 expr := fac.NewCall(
931 1, "cel.@block",
932 fac.NewList(2, []ast.Expr{
933 fac.NewIdent(3, "x"),
934 fac.NewIdent(4, "@index0"),
935 fac.NewIdent(5, "@index1"),
936 }, []int32{}),
937 fac.NewCall(9, operators.Add,
938 fac.NewCall(6, operators.Add,
939 fac.NewIdent(7, "@index2"),
940 fac.NewIdent(8, "@index1")),
941 fac.NewIdent(10, "@index0"),
942 ),
943 )
944 blockAST := ast.NewAST(expr, nil)
945 env, err := cel.NewEnv(
946 Bindings(),
947 cel.Variable("x", cel.StringType),
948 )
949 if err != nil {
950 b.Fatalf("cel.NewEnv(Bindings()) failed: %v", err)
951 }
952 prg, err := env.PlanProgram(blockAST, cel.EvalOptions(cel.OptOptimize))
953 if err != nil {
954 b.Fatalf("PlanProgram() failed: %v", err)
955 }
956 input := map[string]any{"x": "hello"}
957 b.ResetTimer()
958 b.ReportAllocs()
959 for i := 0; i < b.N; i++ {
960 prg.Eval(input)
961 }
962}
963
964func TestValidateBindNestingLimit(t *testing.T) {
965 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