(b *testing.B)
| 529 | } |
| 530 | |
| 531 | func 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 | } |
nothing calls this directly
no test coverage detected