| 176 | } |
| 177 | |
| 178 | void RunBenchmark(const BenchmarkCase& benchmark, benchmark::State& state) { |
| 179 | std::vector<Macro> all_macros = Macro::AllMacros(); |
| 180 | std::vector<Macro> bindings_macros = cel::extensions::bindings_macros(); |
| 181 | all_macros.insert(all_macros.end(), bindings_macros.begin(), |
| 182 | bindings_macros.end()); |
| 183 | ASSERT_OK_AND_ASSIGN( |
| 184 | auto expr, ParseWithMacros(benchmark.expression, all_macros, "<input>")); |
| 185 | |
| 186 | InterpreterOptions options; |
| 187 | auto builder = |
| 188 | google::api::expr::runtime::CreateCelExpressionBuilder(options); |
| 189 | |
| 190 | ASSERT_OK(google::api::expr::runtime::RegisterBuiltinFunctions( |
| 191 | builder->GetRegistry())); |
| 192 | |
| 193 | ASSERT_OK_AND_ASSIGN(auto program, builder->CreateExpression( |
| 194 | &expr.expr(), &expr.source_info())); |
| 195 | |
| 196 | Activation activation; |
| 197 | google::protobuf::Arena arena; |
| 198 | for (auto _ : state) { |
| 199 | auto result = program->Evaluate(activation, &arena); |
| 200 | benchmark::DoNotOptimize(result); |
| 201 | ABSL_DCHECK_OK(result); |
| 202 | ABSL_DCHECK(benchmark.matcher.Matches(*result)); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void BM_Simple(benchmark::State& state) { |
| 207 | RunBenchmark(BenchmarkCases()[0], state); |
no test coverage detected