Series of simple expressions that are expected to require an allocation.
| 98 | |
| 99 | // Series of simple expressions that are expected to require an allocation. |
| 100 | static 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 | } |
| 120 | BENCHMARK(BM_AllocateString); |
| 121 | |
| 122 | static void BM_AllocateError(benchmark::State& state) { |
nothing calls this directly
no test coverage detected