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

Function BM_ListComprehension

eval/tests/modern_benchmark_test.cc:1018–1048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1016BENCHMARK(BM_NestedComprehension_Trace)->Range(1, 1 << 10);
1017
1018void BM_ListComprehension(benchmark::State& state) {
1019 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse("list_var.map(x, x * 2)"));
1020
1021 RuntimeOptions options = GetOptions();
1022 options.comprehension_max_iterations = 10000000;
1023 options.enable_comprehension_list_append = true;
1024 auto runtime = StandardRuntimeOrDie(options);
1025
1026 ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram(
1027 *runtime, parsed_expr));
1028
1029 google::protobuf::Arena arena;
1030 Activation activation;
1031
1032 auto list_builder = cel::NewListValueBuilder(&arena);
1033
1034 int len = state.range(0);
1035 list_builder->Reserve(len);
1036 for (int i = 0; i < len; i++) {
1037 ASSERT_THAT(list_builder->Add(IntValue(1)), IsOk());
1038 }
1039
1040 activation.InsertOrAssignValue("list_var", std::move(*list_builder).Build());
1041
1042 for (auto _ : state) {
1043 ASSERT_OK_AND_ASSIGN(cel::Value result,
1044 cel_expr->Evaluate(&arena, activation));
1045 ASSERT_TRUE(InstanceOf<ListValue>(result));
1046 ASSERT_THAT(Cast<ListValue>(result).Size(), IsOkAndHolds(len));
1047 }
1048}
1049
1050BENCHMARK(BM_ListComprehension)->Range(1, 1 << 16);
1051

Callers

nothing calls this directly

Calls 8

GetOptionsFunction · 0.85
StandardRuntimeOrDieFunction · 0.85
InsertOrAssignValueMethod · 0.80
IntValueClass · 0.50
ReserveMethod · 0.45
AddMethod · 0.45
BuildMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected