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

Function BM_AllocateString

eval/tests/allocation_benchmark_test.cc:100–119  ·  view source on GitHub ↗

Series of simple expressions that are expected to require an allocation.

Source from the content-addressed store, hash-verified

98
99// Series of simple expressions that are expected to require an allocation.
100static void BM_AllocateString(benchmark::State& state) {
101 google::protobuf::Arena arena;
102 std::string expr("'1' + '1'");
103 auto builder = CreateCelExpressionBuilder();
104 ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry()));
105
106 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(expr));
107 ASSERT_OK_AND_ASSIGN(auto cel_expr,
108 builder->CreateExpression(&parsed_expr.expr(),
109 &parsed_expr.source_info()));
110
111 for (auto _ : state) {
112 Activation activation;
113 ASSERT_OK_AND_ASSIGN(CelValue result,
114 cel_expr->Evaluate(activation, &arena));
115 CelValue::StringHolder holder;
116 ASSERT_TRUE(result.GetValue(&holder));
117 ASSERT_EQ(holder.value(), "11");
118 }
119}
120BENCHMARK(BM_AllocateString);
121
122static void BM_AllocateError(benchmark::State& state) {

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