| 65 | } |
| 66 | |
| 67 | void BM_CastDispatchBaseline(benchmark::State& state) { |
| 68 | // Repeatedly invoke a trivial Cast with all dispatch outside the hot loop |
| 69 | random::RandomArrayGenerator rag(kSeed); |
| 70 | |
| 71 | auto int_array = rag.Int64(1, 0, 1 << 20); |
| 72 | auto double_type = float64(); |
| 73 | CastOptions cast_options; |
| 74 | cast_options.to_type = double_type; |
| 75 | ASSERT_OK_AND_ASSIGN(auto cast_function, internal::GetCastFunction(*double_type)); |
| 76 | ASSERT_OK_AND_ASSIGN(auto cast_kernel, |
| 77 | cast_function->DispatchExact({int_array->type()})); |
| 78 | const auto& exec = static_cast<const ScalarKernel*>(cast_kernel)->exec; |
| 79 | |
| 80 | ExecContext exec_context; |
| 81 | KernelContext kernel_context(&exec_context); |
| 82 | auto cast_state = cast_kernel |
| 83 | ->init(&kernel_context, |
| 84 | KernelInitArgs{cast_kernel, {double_type}, &cast_options}) |
| 85 | .ValueOrDie(); |
| 86 | kernel_context.SetState(cast_state.get()); |
| 87 | |
| 88 | ExecSpan input({ExecValue(*int_array->data())}, 1); |
| 89 | ExecResult result; |
| 90 | ASSERT_OK_AND_ASSIGN(std::shared_ptr<Array> result_space, |
| 91 | MakeArrayOfNull(double_type, 1)); |
| 92 | result.array_span_mutable()->SetMembers(*result_space->data()); |
| 93 | for (auto _ : state) { |
| 94 | ABORT_NOT_OK(exec(&kernel_context, input, &result)); |
| 95 | } |
| 96 | |
| 97 | state.SetItemsProcessed(state.iterations() * kScalarCount); |
| 98 | } |
| 99 | |
| 100 | void BM_AddDispatch(benchmark::State& state) { |
| 101 | ExecContext exec_context; |
nothing calls this directly
no test coverage detected