1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 #include "benchmark/benchmark.h"
19
20 #include "arrow/compute/api_vector.h"
21 #include "arrow/compute/kernels/test_util.h"
22 #include "arrow/testing/gtest_util.h"
23 #include "arrow/testing/random.h"
24 #include "arrow/util/benchmark_util.h"
25
26 namespace arrow {
27 namespace compute {
28 constexpr auto kSeed = 0x0ff1ce;
29
NthToIndicesBenchmark(benchmark::State & state,const std::shared_ptr<Array> & values,int64_t n)30 static void NthToIndicesBenchmark(benchmark::State& state,
31 const std::shared_ptr<Array>& values, int64_t n) {
32 for (auto _ : state) {
33 ABORT_NOT_OK(NthToIndices(*values, n).status());
34 }
35 state.SetItemsProcessed(state.iterations() * values->length());
36 }
37
NthToIndicesInt64(benchmark::State & state)38 static void NthToIndicesInt64(benchmark::State& state) {
39 RegressionArgs args(state);
40
41 const int64_t array_size = args.size / sizeof(int64_t);
42 auto rand = random::RandomArrayGenerator(kSeed);
43
44 auto min = std::numeric_limits<int64_t>::min();
45 auto max = std::numeric_limits<int64_t>::max();
46 auto values = rand.Int64(array_size, min, max, args.null_proportion);
47
48 NthToIndicesBenchmark(state, values, array_size / 2);
49 }
50
51 BENCHMARK(NthToIndicesInt64)
52 ->Apply(RegressionSetArgs)
53 ->Args({1 << 20, 100})
54 ->Args({1 << 23, 100})
55 ->MinTime(1.0)
56 ->Unit(benchmark::TimeUnit::kNanosecond);
57
58 } // namespace compute
59 } // namespace arrow
60