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

Function BenchmarkBindings

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

Source from the content-addressed store, hash-verified

218}
219
220func BenchmarkBindings(b *testing.B) {
221 for i, tst := range bindingTests {
222 tc := tst
223 opts := append([]cel.EnvOption{Bindings(), Strings()}, tc.vars...)
224 env, err := cel.NewEnv(opts...)
225 if err != nil {
226 b.Fatalf("cel.NewEnv() failed: %v", err)
227 }
228 ast, iss := env.Compile(tc.expr)
229 if iss.Err() != nil {
230 b.Fatalf("env.Compile(%q) failed: %v", tc.expr, iss.Err())
231 }
232 prg, err := env.Program(ast, cel.EvalOptions(cel.OptOptimize))
233 if err != nil {
234 b.Fatalf("env.Program(ast, Optimize) failed: %v", err)
235 }
236 // Benchmark the eval.
237 b.Run(fmt.Sprintf("[%d]", i), func(b *testing.B) {
238 b.ResetTimer()
239 b.ReportAllocs()
240 var input any = cel.NoVars()
241 if tc.in != nil {
242 input = tc.in
243 }
244 for i := 0; i < b.N; i++ {
245 prg.Eval(input)
246 }
247 })
248 }
249}
250
251func TestBlockEval(t *testing.T) {
252 fac := ast.NewExprFactory()

Callers

nothing calls this directly

Calls 9

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
EvalOptionsFunction · 0.92
NoVarsFunction · 0.92
BindingsFunction · 0.85
StringsFunction · 0.85
ErrMethod · 0.80
EvalMethod · 0.65

Tested by

no test coverage detected