From 18ced4adb2d91725e181276df5a731cbe3da335f Mon Sep 17 00:00:00 2001 From: Frank Du Date: Wed, 12 Aug 2020 06:11:08 +0000 Subject: [PATCH 1/2] Add MinMax kernel benchmark. Also add count. Signed-off-by: Frank Du --- .../compute/kernels/aggregate_benchmark.cc | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc index 71a11458952..c3bba935892 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc @@ -369,5 +369,51 @@ MODE_KERNEL_BENCHMARK(ModeKernelInt16, Int16Type); MODE_KERNEL_BENCHMARK(ModeKernelInt32, Int32Type); MODE_KERNEL_BENCHMARK(ModeKernelInt64, Int64Type); +template +static void MinMaxKernelBench(benchmark::State& state) { + using CType = typename TypeTraits::CType; + + RegressionArgs args(state); + const int64_t array_size = args.size / sizeof(CType); + auto rand = random::RandomArrayGenerator(1923); + auto array = rand.Numeric(array_size, -100, 100, args.null_proportion); + + for (auto _ : state) { + ABORT_NOT_OK(MinMax(array).status()); + } +} + +static void MinMaxKernelBenchArgs(benchmark::internal::Benchmark* bench) { + BenchmarkSetArgsWithSizes(bench, {1 * 1024 * 1024}); // 1M +} + +#define MINMAX_KERNEL_BENCHMARK(FuncName, Type) \ + static void FuncName(benchmark::State& state) { MinMaxKernelBench(state); } \ + BENCHMARK(FuncName)->Apply(MinMaxKernelBenchArgs) + +MINMAX_KERNEL_BENCHMARK(MinMaxKernelFloat, FloatType); +MINMAX_KERNEL_BENCHMARK(MinMaxKernelDouble, DoubleType); +MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt8, Int8Type); +MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt16, Int16Type); +MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt32, Int32Type); +MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt64, Int64Type); + +static void CountKernelInt64(benchmark::State& state) { + RegressionArgs args(state); + const int64_t array_size = args.size / sizeof(int64_t); + auto rand = random::RandomArrayGenerator(1923); + auto array = rand.Numeric(array_size, -100, 100, args.null_proportion); + + for (auto _ : state) { + ABORT_NOT_OK(Count(array).status()); + } +} + +static void CountKernelBenchArgs(benchmark::internal::Benchmark* bench) { + BenchmarkSetArgsWithSizes(bench, {1 * 1024 * 1024}); // 1M +} + +BENCHMARK(CountKernelInt64)->Apply(CountKernelBenchArgs); + } // namespace compute } // namespace arrow From 0b9de250ad2f69a97a1e97089431a720bda0c9f5 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 12 Aug 2020 19:11:02 +0200 Subject: [PATCH 2/2] Remove meaningless Count benchmark (it's a trivial constant-time operation) --- .../compute/kernels/aggregate_benchmark.cc | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc index c3bba935892..882037f2d5d 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc @@ -398,22 +398,5 @@ MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt16, Int16Type); MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt32, Int32Type); MINMAX_KERNEL_BENCHMARK(MinMaxKernelInt64, Int64Type); -static void CountKernelInt64(benchmark::State& state) { - RegressionArgs args(state); - const int64_t array_size = args.size / sizeof(int64_t); - auto rand = random::RandomArrayGenerator(1923); - auto array = rand.Numeric(array_size, -100, 100, args.null_proportion); - - for (auto _ : state) { - ABORT_NOT_OK(Count(array).status()); - } -} - -static void CountKernelBenchArgs(benchmark::internal::Benchmark* bench) { - BenchmarkSetArgsWithSizes(bench, {1 * 1024 * 1024}); // 1M -} - -BENCHMARK(CountKernelInt64)->Apply(CountKernelBenchArgs); - } // namespace compute } // namespace arrow