Benchmark test Traces cel expression with an empty callback: '1 + 1 + 1 .... +1'
| 168 | // Traces cel expression with an empty callback: |
| 169 | // '1 + 1 + 1 .... +1' |
| 170 | static void BM_Eval_Trace(benchmark::State& state) { |
| 171 | RuntimeOptions options = GetOptions(); |
| 172 | options.enable_recursive_tracing = true; |
| 173 | |
| 174 | auto runtime = StandardRuntimeOrDie(options); |
| 175 | |
| 176 | int len = state.range(0); |
| 177 | |
| 178 | Expr root_expr; |
| 179 | Expr* cur_expr = &root_expr; |
| 180 | |
| 181 | for (int i = 0; i < len; i++) { |
| 182 | Expr::Call* call = cur_expr->mutable_call_expr(); |
| 183 | call->set_function("_+_"); |
| 184 | call->add_args()->mutable_const_expr()->set_int64_value(1); |
| 185 | cur_expr = call->add_args(); |
| 186 | } |
| 187 | |
| 188 | cur_expr->mutable_const_expr()->set_int64_value(1); |
| 189 | |
| 190 | SourceInfo source_info; |
| 191 | ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram( |
| 192 | *runtime, root_expr)); |
| 193 | |
| 194 | for (auto _ : state) { |
| 195 | google::protobuf::Arena arena; |
| 196 | Activation activation; |
| 197 | ASSERT_OK_AND_ASSIGN(cel::Value result, |
| 198 | cel_expr->Trace(&arena, activation, EmptyCallback)); |
| 199 | ASSERT_TRUE(InstanceOf<IntValue>(result)); |
| 200 | ASSERT_TRUE(Cast<IntValue>(result) == len + 1); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // A number higher than 10k leads to a stack overflow due to the recursive |
| 205 | // nature of the proto to native type conversion. |
no test coverage detected