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

Function BM_StrCatLocalArena

eval/tests/allocation_benchmark_test.cc:41–65  ·  view source on GitHub ↗

Evaluates cel expression: '"1" + "1" + ...'

Source from the content-addressed store, hash-verified

39// Evaluates cel expression:
40// '"1" + "1" + ...'
41static void BM_StrCatLocalArena(benchmark::State& state) {
42 std::string expr("'1'");
43 int len = state.range(0);
44 auto builder = CreateCelExpressionBuilder();
45 ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry()));
46
47 for (int i = 0; i < len; i++) {
48 expr = absl::Substitute("($0 + $0)", expr);
49 }
50
51 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(expr));
52 ASSERT_OK_AND_ASSIGN(auto cel_expr,
53 builder->CreateExpression(&parsed_expr.expr(),
54 &parsed_expr.source_info()));
55
56 for (auto _ : state) {
57 google::protobuf::Arena arena;
58 Activation activation;
59 ASSERT_OK_AND_ASSIGN(CelValue result,
60 cel_expr->Evaluate(activation, &arena));
61 CelValue::StringHolder holder;
62 ASSERT_TRUE(result.GetValue(&holder));
63 ASSERT_EQ(holder.value().length(), 1 << len);
64 }
65}
66BENCHMARK(BM_StrCatLocalArena)->DenseRange(0, 8, 2);
67
68// Evaluates cel expression:

Callers

nothing calls this directly

Calls 5

RegisterBuiltinFunctionsFunction · 0.85
GetRegistryMethod · 0.80
GetValueMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected