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

Function BenchmarkContextEval

cel/cel_test.go:1214–1241  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1212}
1213
1214func BenchmarkContextEval(b *testing.B) {
1215 env := testEnv(b,
1216 Variable("items", ListType(IntType)),
1217 )
1218 ast, iss := env.Compile("items.map(i, i * 2).filter(i, i >= 50).size()")
1219 if iss.Err() != nil {
1220 b.Fatalf("env.Compile(expr) failed: %v", iss.Err())
1221 }
1222 prg, err := env.Program(ast, EvalOptions(OptOptimize), InterruptCheckFrequency(200))
1223 if err != nil {
1224 b.Fatalf("env.Program() failed: %v", err)
1225 }
1226
1227 ctx := context.TODO()
1228 items := make([]int64, 100)
1229 for i := int64(0); i < 100; i++ {
1230 items[i] = i
1231 }
1232 for i := 0; i < b.N; i++ {
1233 out, _, err := prg.ContextEval(ctx, map[string]any{"items": items})
1234 if err != nil {
1235 b.Fatalf("prg.ContextEval() failed: %v", err)
1236 }
1237 if out != types.Int(75) {
1238 b.Errorf("prg.ContextEval() got %v, wanted 75", out)
1239 }
1240 }
1241}
1242
1243func TestEvalRecover(t *testing.T) {
1244 e := testEnv(t,

Callers

nothing calls this directly

Calls 9

IntTypeAlias · 0.92
EvalOptionsFunction · 0.85
InterruptCheckFrequencyFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
ContextEvalMethod · 0.65

Tested by

no test coverage detected