| 98 | } |
| 99 | |
| 100 | void 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 | |
| 115 | static 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 | |
| 128 | void 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 | |
| 152 | void 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 |
nothing calls this directly
no test coverage detected