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

Function BM_EvalString

eval/tests/modern_benchmark_test.cc:211–242  ·  view source on GitHub ↗

Benchmark test Evaluates cel expression: '"a" + "a" + "a" .... + "a"'

Source from the content-addressed store, hash-verified

209// Evaluates cel expression:
210// '"a" + "a" + "a" .... + "a"'
211static 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.

Callers

nothing calls this directly

Calls 4

GetOptionsFunction · 0.85
StandardRuntimeOrDieFunction · 0.85
set_functionMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected