MCPcopy Create free account
hub / github.com/apache/arrow / BM_AddDispatch

Function BM_AddDispatch

cpp/src/arrow/compute/function_benchmark.cc:100–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void BM_AddDispatch(benchmark::State& state) {
101 ExecContext exec_context;
102 KernelContext kernel_context(&exec_context);
103
104 for (auto _ : state) {
105 ASSERT_OK_AND_ASSIGN(auto add_function, GetFunctionRegistry()->GetFunction("add"));
106 ASSERT_OK_AND_ASSIGN(auto add_kernel,
107 checked_cast<const ScalarFunction&>(*add_function)
108 .DispatchExact({int64(), int64()}));
109 benchmark::DoNotOptimize(add_kernel);
110 }
111
112 state.SetItemsProcessed(state.iterations());
113}
114
115static ScalarVector MakeScalarsForIsValid(int64_t nitems) {
116 std::vector<std::shared_ptr<Scalar>> scalars;
117 scalars.reserve(nitems);
118 for (int64_t i = 0; i < nitems; ++i) {
119 if (i & 0x10) {
120 scalars.emplace_back(MakeNullScalar(int64()));
121 } else {
122 scalars.emplace_back(*MakeScalar(int64(), i));
123 }
124 }
125 return scalars;
126}
127
128void BM_ExecuteScalarFunctionOnScalar(benchmark::State& state) {
129 // Execute a trivial function, with argument dispatch in the hot path
130 const int64_t N = 10000;
131
132 auto function = checked_pointer_cast<ScalarFunction>(
133 *GetFunctionRegistry()->GetFunction("is_valid"));
134 const auto scalars = MakeScalarsForIsValid(N);
135
136 ExecContext exec_context;
137 KernelContext kernel_context(&exec_context);
138
139 for (auto _ : state) {
140 int64_t total = 0;
141 for (const auto& scalar : scalars) {
142 const Datum result =
143 *function->Execute({Datum(scalar)}, function->default_options(), &exec_context);
144 total += result.scalar()->is_valid;
145 }
146 benchmark::DoNotOptimize(total);
147 }
148
149 state.SetItemsProcessed(state.iterations() * N);
150}
151
152void BM_ExecuteScalarKernelOnScalar(benchmark::State& state) {
153 // Execute a trivial function, with argument dispatch outside the hot path
154 auto function = *GetFunctionRegistry()->GetFunction("is_valid");
155 auto kernel = *function->DispatchExact({int64()});
156 const auto& exec = static_cast<const ScalarKernel&>(*kernel).exec;
157

Callers

nothing calls this directly

Calls 15

MakeNullScalarFunction · 0.85
MakeScalarFunction · 0.85
GetFunctionRegistryFunction · 0.85
MakeArrayOfNullFunction · 0.85
emplace_backMethod · 0.80
SetMembersMethod · 0.80
RangeMethod · 0.80
DatumClass · 0.70
ASSERT_OK_AND_ASSIGNFunction · 0.70
ifFunction · 0.50
GetFunctionMethod · 0.45
ExecuteMethod · 0.45

Tested by

no test coverage detected