Skip to content

Commit

Permalink
apacheGH-15200: [C++] Created benchmarks for round kernels. (apache#1…
Browse files Browse the repository at this point in the history
…5201)

The four existing kernel functions Ceil, Floor, Round, and Trunc gain benchmarks with this change.
* Closes: apache#15200

Lead-authored-by: David Sisson <EpsilonPrime@users.noreply.github.com>
Co-authored-by: Will Jones <willjones127@gmail.com>
Signed-off-by: Yibo Cai <yibo.cai@arm.com>
  • Loading branch information
EpsilonPrime and wjones127 committed Jan 10, 2023
1 parent 0c59f6c commit fac1f48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_arithmetic_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ static void ArrayArrayKernel(benchmark::State& state) {
}

void SetArgs(benchmark::internal::Benchmark* bench) {
bench->ArgNames({"size", "inverse_null_proportion"});

for (const auto inverse_null_proportion : std::vector<ArgsType>({100, 0})) {
bench->Args({static_cast<ArgsType>(kL2Size), inverse_null_proportion});
}
Expand Down
15 changes: 12 additions & 3 deletions cpp/src/arrow/compute/kernels/scalar_round_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ static void RoundArrayBenchmark(benchmark::State& state, const std::string& func
}

void SetRoundArgs(benchmark::internal::Benchmark* bench) {
bench->ArgNames({"size", "inverse_null_proportion"});

for (const auto inverse_null_proportion : std::vector<ArgsType>({100, 0})) {
bench->Args({static_cast<ArgsType>(kL2Size), inverse_null_proportion});
}
Expand All @@ -65,19 +67,20 @@ static void Ceil(benchmark::State& state) {

template <typename ArrowType, RoundMode Mode>
static void Floor(benchmark::State& state) {
RoundArrayBenchmark<FloatType, Mode>(state, "floor");
RoundArrayBenchmark<ArrowType, Mode>(state, "floor");
}

template <typename ArrowType, RoundMode Mode>
static void Round(benchmark::State& state) {
RoundArrayBenchmark<FloatType, Mode>(state, "round");
RoundArrayBenchmark<ArrowType, Mode>(state, "round");
}

template <typename ArrowType, RoundMode Mode>
static void Trunc(benchmark::State& state) {
RoundArrayBenchmark<FloatType, Mode>(state, "trunc");
RoundArrayBenchmark<ArrowType, Mode>(state, "trunc");
}

#ifdef ALL_ROUND_BENCHMARKS
#define DECLARE_ROUND_BENCHMARKS_WITH_ROUNDMODE(OP, TYPE) \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::DOWN)->Apply(SetRoundArgs); \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::UP)->Apply(SetRoundArgs); \
Expand All @@ -89,6 +92,12 @@ static void Trunc(benchmark::State& state) {
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::HALF_TOWARDS_INFINITY)->Apply(SetRoundArgs); \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::HALF_TO_EVEN)->Apply(SetRoundArgs); \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::HALF_TO_ODD)->Apply(SetRoundArgs)
#else
#define DECLARE_ROUND_BENCHMARKS_WITH_ROUNDMODE(OP, TYPE) \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::DOWN)->Apply(SetRoundArgs); \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::HALF_TOWARDS_ZERO)->Apply(SetRoundArgs); \
BENCHMARK_TEMPLATE(OP, TYPE, RoundMode::HALF_TO_ODD)->Apply(SetRoundArgs)
#endif

#define DECLARE_ROUND_BENCHMARKS(OP) \
DECLARE_ROUND_BENCHMARKS_WITH_ROUNDMODE(OP, Int64Type); \
Expand Down

0 comments on commit fac1f48

Please sign in to comment.