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

Function BM_ListComprehension

eval/tests/benchmark_test.cc:920–949  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

918BENCHMARK(BM_NestedComprehension_Trace)->Range(1, 1 << 10);
919
920void BM_ListComprehension(benchmark::State& state) {
921 google::protobuf::Arena arena;
922 Activation activation;
923 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr,
924 parser::Parse("list_var.map(x, x * 2)"));
925
926 int len = state.range(0);
927 std::vector<CelValue> list;
928 list.reserve(len);
929 for (int i = 0; i < len; i++) {
930 list.push_back(CelValue::CreateInt64(1));
931 }
932
933 ContainerBackedListImpl cel_list(std::move(list));
934 activation.InsertValue("list_var", CelValue::CreateList(&cel_list));
935 InterpreterOptions options = GetOptions(arena);
936 options.comprehension_max_iterations = 10000000;
937 options.enable_comprehension_list_append = true;
938 auto builder = CreateCelExpressionBuilder(options);
939 ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry(), options));
940 ASSERT_OK_AND_ASSIGN(
941 auto cel_expr, builder->CreateExpression(&(parsed_expr.expr()), nullptr));
942
943 for (auto _ : state) {
944 ASSERT_OK_AND_ASSIGN(CelValue result,
945 cel_expr->Evaluate(activation, &arena));
946 ASSERT_TRUE(result.IsList());
947 ASSERT_EQ(result.ListOrDie()->size(), len);
948 }
949}
950
951BENCHMARK(BM_ListComprehension)->Range(1, 1 << 16);
952

Callers

nothing calls this directly

Calls 9

GetOptionsFunction · 0.85
RegisterBuiltinFunctionsFunction · 0.85
InsertValueMethod · 0.80
GetRegistryMethod · 0.80
ListOrDieMethod · 0.80
CreateListFunction · 0.50
IsListMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected