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

Function BM_Eval_Trace

eval/tests/modern_benchmark_test.cc:170–202  ·  view source on GitHub ↗

Benchmark test Traces cel expression with an empty callback: '1 + 1 + 1 .... +1'

Source from the content-addressed store, hash-verified

168// Traces cel expression with an empty callback:
169// '1 + 1 + 1 .... +1'
170static void BM_Eval_Trace(benchmark::State& state) {
171 RuntimeOptions options = GetOptions();
172 options.enable_recursive_tracing = true;
173
174 auto runtime = StandardRuntimeOrDie(options);
175
176 int len = state.range(0);
177
178 Expr root_expr;
179 Expr* cur_expr = &root_expr;
180
181 for (int i = 0; i < len; i++) {
182 Expr::Call* call = cur_expr->mutable_call_expr();
183 call->set_function("_+_");
184 call->add_args()->mutable_const_expr()->set_int64_value(1);
185 cur_expr = call->add_args();
186 }
187
188 cur_expr->mutable_const_expr()->set_int64_value(1);
189
190 SourceInfo source_info;
191 ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram(
192 *runtime, root_expr));
193
194 for (auto _ : state) {
195 google::protobuf::Arena arena;
196 Activation activation;
197 ASSERT_OK_AND_ASSIGN(cel::Value result,
198 cel_expr->Trace(&arena, activation, EmptyCallback));
199 ASSERT_TRUE(InstanceOf<IntValue>(result));
200 ASSERT_TRUE(Cast<IntValue>(result) == len + 1);
201 }
202}
203
204// A number higher than 10k leads to a stack overflow due to the recursive
205// nature of the proto to native type conversion.

Callers 1

ABSL_FLAGFunction · 0.85

Calls 3

GetOptionsFunction · 0.85
StandardRuntimeOrDieFunction · 0.85
set_functionMethod · 0.80

Tested by

no test coverage detected