MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ABSL_FLAG

Function ABSL_FLAG

eval/tests/benchmark_test.cc:32–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#include "google/protobuf/text_format.h"
31
32ABSL_FLAG(bool, enable_optimizations, false, "enable const folding opt");
33ABSL_FLAG(bool, enable_recursive_planning, false, "enable recursive planning");
34
35namespace google {
36namespace api {
37namespace expr {
38namespace runtime {
39
40namespace {
41
42using ::cel::expr::Expr;
43using ::cel::expr::ParsedExpr;
44using ::cel::expr::SourceInfo;
45using ::google::rpc::context::AttributeContext;
46
47InterpreterOptions GetOptions(google::protobuf::Arena& arena) {
48 InterpreterOptions options;
49
50 if (absl::GetFlag(FLAGS_enable_optimizations)) {
51 options.constant_arena = &arena;
52 options.constant_folding = true;
53 }
54
55 if (absl::GetFlag(FLAGS_enable_recursive_planning)) {
56 options.max_recursion_depth = -1;
57 }
58
59 return options;
60}
61
62// Benchmark test
63// Evaluates cel expression:
64// '1 + 1 + 1 .... +1'
65static void BM_Eval(benchmark::State& state) {
66 google::protobuf::Arena arena;
67 InterpreterOptions options = GetOptions(arena);
68
69 auto builder = CreateCelExpressionBuilder(options);
70 ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry(), options));
71
72 int len = state.range(0);
73
74 Expr root_expr;
75 Expr* cur_expr = &root_expr;
76
77 for (int i = 0; i < len; i++) {
78 Expr::Call* call = cur_expr->mutable_call_expr();
79 call->set_function("_+_");
80 call->add_args()->mutable_const_expr()->set_int64_value(1);
81 cur_expr = call->add_args();
82 }
83
84 cur_expr->mutable_const_expr()->set_int64_value(1);
85
86 SourceInfo source_info;
87 ASSERT_OK_AND_ASSIGN(auto cel_expr,
88 builder->CreateExpression(&root_expr, &source_info));
89

Callers

nothing calls this directly

Calls 15

BM_EvalFunction · 0.85
GetOptionsFunction · 0.85
RegisterBuiltinFunctionsFunction · 0.85
EmptyCallbackFunction · 0.85
BM_Eval_TraceFunction · 0.85
GetRegistryMethod · 0.80
set_functionMethod · 0.80
IsInt64Method · 0.80
Int64OrDieMethod · 0.80
StringOrDieMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70

Tested by

no test coverage detected