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

Function BenchmarkBlockEval

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

Source from the content-addressed store, hash-verified

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

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