kszucs commented on a change in pull request #7417: URL: https://github.com/apache/arrow/pull/7417#discussion_r439371127
########## File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_benchmark.cc ########## @@ -0,0 +1,92 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "benchmark/benchmark.h" + +#include <vector> + +#include "arrow/compute/api_scalar.h" +#include "arrow/compute/benchmark_util.h" +#include "arrow/compute/kernels/test_util.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" + +namespace arrow { +namespace compute { + +constexpr auto kSeed = 0x94378165; + +template <typename ArrowType, typename CType = typename ArrowType::c_type> +static void AddArrayScalarKernel(benchmark::State& state) { + RegressionArgs args(state); + + const int64_t array_size = args.size / sizeof(CType); + auto min = std::numeric_limits<CType>::lowest(); + auto max = std::numeric_limits<CType>::max(); + + auto rand = random::RandomArrayGenerator(kSeed); + auto lhs = std::static_pointer_cast<NumericArray<ArrowType>>( + rand.Numeric<ArrowType>(array_size, min, max, args.null_proportion)); + + for (auto _ : state) { + ABORT_NOT_OK(Add(lhs, Datum(CType(15))).status()); + } +} + +template <typename ArrowType, typename CType = typename ArrowType::c_type> +static void AddArrayArrayKernel(benchmark::State& state) { + RegressionArgs args(state); + + const int64_t array_size = args.size / sizeof(CType); + auto min = std::numeric_limits<CType>::lowest(); + auto max = std::numeric_limits<CType>::max(); + + auto rand = random::RandomArrayGenerator(kSeed); + auto lhs = std::static_pointer_cast<NumericArray<ArrowType>>( + rand.Numeric<ArrowType>(array_size, min, max, args.null_proportion)); + auto rhs = std::static_pointer_cast<NumericArray<ArrowType>>( + rand.Numeric<ArrowType>(array_size, min, max, args.null_proportion)); + + for (auto _ : state) { + ABORT_NOT_OK(Add(lhs, rhs).status()); + } +} + +BENCHMARK_TEMPLATE(AddArrayArrayKernel, Int64Type)->Apply(RegressionSetArgs); Review comment: @bkietz I assume it would be better to parametrize the benchmark over the binary operator (`Add`, `Subtract`, `Multiply`), although I don't know how to pass both define a template parameter and pass an argument to gbench. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org