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

Function BM_EvalString_Trace

eval/tests/modern_benchmark_test.cc:251–283  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

249// Traces cel expression with an empty callback:
250// '"a" + "a" + "a" .... + "a"'
251static void BM_EvalString_Trace(benchmark::State& state) {
252 RuntimeOptions options = GetOptions();
253 options.enable_recursive_tracing = true;
254
255 auto runtime = StandardRuntimeOrDie(options);
256
257 int len = state.range(0);
258
259 Expr root_expr;
260 Expr* cur_expr = &root_expr;
261
262 for (int i = 0; i < len; i++) {
263 Expr::Call* call = cur_expr->mutable_call_expr();
264 call->set_function("_+_");
265 call->add_args()->mutable_const_expr()->set_string_value("a");
266 cur_expr = call->add_args();
267 }
268
269 cur_expr->mutable_const_expr()->set_string_value("a");
270
271 SourceInfo source_info;
272 ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram(
273 *runtime, root_expr));
274
275 for (auto _ : state) {
276 google::protobuf::Arena arena;
277 Activation activation;
278 ASSERT_OK_AND_ASSIGN(cel::Value result,
279 cel_expr->Trace(&arena, activation, EmptyCallback));
280 ASSERT_TRUE(InstanceOf<StringValue>(result));
281 ASSERT_TRUE(Cast<StringValue>(result).Size() == len + 1);
282 }
283}
284
285// A number higher than 10k leads to a stack overflow due to the recursive
286// nature of the proto to native type conversion.

Callers

nothing calls this directly

Calls 4

GetOptionsFunction · 0.85
StandardRuntimeOrDieFunction · 0.85
set_functionMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected