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

Function BenchmarkEvalOptions

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

Source from the content-addressed store, hash-verified

1566}
1567
1568func BenchmarkEvalOptions(b *testing.B) {
1569 env := testEnv(b,
1570 Variable("ai", IntType),
1571 Variable("ar", MapType(StringType, StringType)),
1572 )
1573 ast, _ := env.Compile("ai == 20 || ar['foo'] == 'bar'")
1574 vars := map[string]any{
1575 "ai": 2,
1576 "ar": map[string]string{
1577 "foo": "bar",
1578 },
1579 }
1580
1581 opts := map[string]EvalOption{
1582 "track-state": OptTrackState,
1583 "exhaustive-eval": OptExhaustiveEval,
1584 "optimize": OptOptimize,
1585 }
1586 for k, opt := range opts {
1587 b.Run(k, func(bb *testing.B) {
1588 prg, err := env.Program(ast, EvalOptions(opt))
1589 if err != nil {
1590 b.Fatalf("env.Program() failed: %v", err)
1591 }
1592 b.ResetTimer()
1593 b.ReportAllocs()
1594 for i := 0; i < bb.N; i++ {
1595 _, _, err := prg.Eval(vars)
1596 if err != nil {
1597 b.Fatal(err)
1598 }
1599 }
1600 })
1601 }
1602}
1603
1604func TestEnvExtension(t *testing.T) {
1605 env := testEnv(t,

Callers

nothing calls this directly

Calls 6

EvalOptionsFunction · 0.85
ProgramMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected