Benchmark test Evaluates cel expression: '"a" + "a" + "a" .... + "a"'
| 209 | // Evaluates cel expression: |
| 210 | // '"a" + "a" + "a" .... + "a"' |
| 211 | static void BM_EvalString(benchmark::State& state) { |
| 212 | RuntimeOptions options = GetOptions(); |
| 213 | |
| 214 | auto runtime = StandardRuntimeOrDie(options); |
| 215 | |
| 216 | int len = state.range(0); |
| 217 | |
| 218 | Expr root_expr; |
| 219 | Expr* cur_expr = &root_expr; |
| 220 | |
| 221 | for (int i = 0; i < len; i++) { |
| 222 | Expr::Call* call = cur_expr->mutable_call_expr(); |
| 223 | call->set_function("_+_"); |
| 224 | call->add_args()->mutable_const_expr()->set_string_value("a"); |
| 225 | cur_expr = call->add_args(); |
| 226 | } |
| 227 | |
| 228 | cur_expr->mutable_const_expr()->set_string_value("a"); |
| 229 | |
| 230 | SourceInfo source_info; |
| 231 | ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram( |
| 232 | *runtime, root_expr)); |
| 233 | |
| 234 | for (auto _ : state) { |
| 235 | google::protobuf::Arena arena; |
| 236 | Activation activation; |
| 237 | ASSERT_OK_AND_ASSIGN(cel::Value result, |
| 238 | cel_expr->Evaluate(&arena, activation)); |
| 239 | ASSERT_TRUE(InstanceOf<StringValue>(result)); |
| 240 | ASSERT_TRUE(Cast<StringValue>(result).Size() == len + 1); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // A number higher than 10k leads to a stack overflow due to the recursive |
| 245 | // nature of the proto to native type conversion. |
nothing calls this directly
no test coverage detected