pitrou commented on code in PR #41036:
URL: https://github.com/apache/arrow/pull/41036#discussion_r1561087733


##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type

Review Comment:
   That's gonna produce a lot of different groups if there's a string key, 
right? Is it realistic?



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type
+      });
+  // clang-format on
+
+  std::vector<Datum> values;
+  values.resize(num_types);
+  for (int i = 0; i < num_types; ++i) {
+    auto field = ::arrow::field("", types[i], metadata);
+    values[i] = rng.ArrayOf(*field, num_rows, alignment, memory_pool);
+  }
+
+  return ExecBatch(std::move(values), num_rows);
+}
+
+static void GrouperBenchmark(benchmark::State& state, const ExecSpan& span,
+                             ExecContext* ctx = nullptr) {
+  for (auto _ : state) {
+    ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
+    for (int i = 0; i < kRound; ++i) {
+      ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
+    }
+  }
+
+  state.SetItemsProcessed(state.iterations() * kRound * span.length);
+}
+
+static void GrouperWithMultiTypes(benchmark::State& state, const 
DataTypeVector& types) {
+  auto ctx = default_exec_context();
+
+  RegressionArgs args(state, false);
+  const int64_t num_rows = args.size;
+  const double null_proportion = args.null_proportion;
+
+  auto exec_batch = MakeRandomExecBatch(types, num_rows, null_proportion,
+                                        kDefaultBufferAlignment, 
ctx->memory_pool());
+  ExecSpan exec_span(exec_batch);
+  ASSIGN_OR_ABORT(auto grouper, Grouper::Make(exec_span.GetTypes(), ctx));
+  GrouperBenchmark(state, exec_span, ctx);
+}
+
+void SetArgs(benchmark::internal::Benchmark* bench) {
+  BenchmarkSetArgsWithSizes(bench, {1 << 10, 1 << 12});
+}
+
+// basic type column
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean}", 
{boolean()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32}", {int32()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int64}", {int64()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{utf8}", {utf8()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{fixed_size_binary(128)}",
+                  {fixed_size_binary(128)})
+    ->Apply(SetArgs);
+
+// multi types' columns
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, utf8}", {boolean(), 
utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int32}", {int32(), int32()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int64}", {int32(), int64()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, int64, utf8}",
+                  {boolean(), int64(), utf8()})
+    ->Apply(SetArgs);
+
+// multi types' columns with column resorted

Review Comment:
   What does "resorted" mean here? Do you mean the columns are in a different 
order?



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"

Review Comment:
   This is a third-party include, can move it above and use brackets (`#include 
<benchmark/benchmark.h>`)?



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type

Review Comment:
   We probably shouldn't make `true_probability` the same as `null_probability` 
(as it makes the data trivial if `null_probability` is either 0.0 or 1.0), how 
about a hardcoded value such as 0.2?



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type
+      });
+  // clang-format on
+
+  std::vector<Datum> values;
+  values.resize(num_types);
+  for (int i = 0; i < num_types; ++i) {
+    auto field = ::arrow::field("", types[i], metadata);
+    values[i] = rng.ArrayOf(*field, num_rows, alignment, memory_pool);
+  }
+
+  return ExecBatch(std::move(values), num_rows);
+}
+
+static void GrouperBenchmark(benchmark::State& state, const ExecSpan& span,
+                             ExecContext* ctx = nullptr) {
+  for (auto _ : state) {
+    ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
+    for (int i = 0; i < kRound; ++i) {
+      ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
+    }
+  }
+
+  state.SetItemsProcessed(state.iterations() * kRound * span.length);
+}
+
+static void GrouperWithMultiTypes(benchmark::State& state, const 
DataTypeVector& types) {
+  auto ctx = default_exec_context();
+
+  RegressionArgs args(state, false);
+  const int64_t num_rows = args.size;
+  const double null_proportion = args.null_proportion;
+
+  auto exec_batch = MakeRandomExecBatch(types, num_rows, null_proportion,
+                                        kDefaultBufferAlignment, 
ctx->memory_pool());
+  ExecSpan exec_span(exec_batch);
+  ASSIGN_OR_ABORT(auto grouper, Grouper::Make(exec_span.GetTypes(), ctx));
+  GrouperBenchmark(state, exec_span, ctx);
+}
+
+void SetArgs(benchmark::internal::Benchmark* bench) {
+  BenchmarkSetArgsWithSizes(bench, {1 << 10, 1 << 12});
+}
+
+// basic type column
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean}", 
{boolean()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32}", {int32()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int64}", {int64()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{utf8}", {utf8()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{fixed_size_binary(128)}",
+                  {fixed_size_binary(128)})
+    ->Apply(SetArgs);
+
+// multi types' columns
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, utf8}", {boolean(), 
utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int32}", {int32(), int32()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int64}", {int32(), int64()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, int64, utf8}",
+                  {boolean(), int64(), utf8()})
+    ->Apply(SetArgs);
+
+// multi types' columns with column resorted
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, boolean, utf8}",
+                  {int32(), boolean(), utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int64, boolean, utf8}",
+                  {int32(), int64(), boolean(), utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes,
+                  "{utf8, int32, int64, fixed_size_binary(128), boolean}",
+                  {utf8(), int32(), int64(), fixed_size_binary(128), 
boolean()})
+    ->Apply(SetArgs);

Review Comment:
   Do we really need to benchmark so many different type combinations? Do these 
benchmarks exercise some particular edge cases?



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type
+      });
+  // clang-format on
+
+  std::vector<Datum> values;
+  values.resize(num_types);
+  for (int i = 0; i < num_types; ++i) {
+    auto field = ::arrow::field("", types[i], metadata);
+    values[i] = rng.ArrayOf(*field, num_rows, alignment, memory_pool);
+  }
+
+  return ExecBatch(std::move(values), num_rows);
+}
+
+static void GrouperBenchmark(benchmark::State& state, const ExecSpan& span,
+                             ExecContext* ctx = nullptr) {
+  for (auto _ : state) {
+    ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
+    for (int i = 0; i < kRound; ++i) {
+      ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
+    }
+  }
+
+  state.SetItemsProcessed(state.iterations() * kRound * span.length);
+}
+
+static void GrouperWithMultiTypes(benchmark::State& state, const 
DataTypeVector& types) {
+  auto ctx = default_exec_context();
+
+  RegressionArgs args(state, false);
+  const int64_t num_rows = args.size;
+  const double null_proportion = args.null_proportion;
+
+  auto exec_batch = MakeRandomExecBatch(types, num_rows, null_proportion,
+                                        kDefaultBufferAlignment, 
ctx->memory_pool());
+  ExecSpan exec_span(exec_batch);
+  ASSIGN_OR_ABORT(auto grouper, Grouper::Make(exec_span.GetTypes(), ctx));
+  GrouperBenchmark(state, exec_span, ctx);
+}
+
+void SetArgs(benchmark::internal::Benchmark* bench) {
+  BenchmarkSetArgsWithSizes(bench, {1 << 10, 1 << 12});
+}
+
+// basic type column
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean}", 
{boolean()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32}", {int32()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int64}", {int64()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{utf8}", {utf8()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{fixed_size_binary(128)}",

Review Comment:
   Is 128 bytes a frequent size for fixed_size_binary? Intuitively, I would 
have guessed much shorter sizes are more common, e.g. 16, 20 or 32 (for 
decimals, uuids or sha160s, for example).



##########
cpp/src/arrow/compute/CMakeLists.txt:
##########
@@ -95,6 +95,7 @@ add_arrow_test(internals_test
 add_arrow_compute_test(expression_test SOURCES expression_test.cc)
 
 add_arrow_benchmark(function_benchmark PREFIX "arrow-compute")
+add_arrow_benchmark(row/grouper_benchmark PREFIX "arrow-compute")

Review Comment:
   Can you move this into `row/CMakeLists.txt`



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type
+      });
+  // clang-format on
+
+  std::vector<Datum> values;
+  values.resize(num_types);
+  for (int i = 0; i < num_types; ++i) {
+    auto field = ::arrow::field("", types[i], metadata);
+    values[i] = rng.ArrayOf(*field, num_rows, alignment, memory_pool);
+  }
+
+  return ExecBatch(std::move(values), num_rows);
+}
+
+static void GrouperBenchmark(benchmark::State& state, const ExecSpan& span,
+                             ExecContext* ctx = nullptr) {
+  for (auto _ : state) {
+    ASSIGN_OR_ABORT(auto grouper, Grouper::Make(span.GetTypes(), ctx));
+    for (int i = 0; i < kRound; ++i) {
+      ASSIGN_OR_ABORT(auto group_ids, grouper->Consume(span));
+    }
+  }
+
+  state.SetItemsProcessed(state.iterations() * kRound * span.length);
+}
+
+static void GrouperWithMultiTypes(benchmark::State& state, const 
DataTypeVector& types) {
+  auto ctx = default_exec_context();
+
+  RegressionArgs args(state, false);
+  const int64_t num_rows = args.size;
+  const double null_proportion = args.null_proportion;
+
+  auto exec_batch = MakeRandomExecBatch(types, num_rows, null_proportion,
+                                        kDefaultBufferAlignment, 
ctx->memory_pool());
+  ExecSpan exec_span(exec_batch);
+  ASSIGN_OR_ABORT(auto grouper, Grouper::Make(exec_span.GetTypes(), ctx));
+  GrouperBenchmark(state, exec_span, ctx);
+}
+
+void SetArgs(benchmark::internal::Benchmark* bench) {
+  BenchmarkSetArgsWithSizes(bench, {1 << 10, 1 << 12});
+}
+
+// basic type column
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean}", 
{boolean()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32}", {int32()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int64}", {int64()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{utf8}", {utf8()})->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{fixed_size_binary(128)}",
+                  {fixed_size_binary(128)})
+    ->Apply(SetArgs);
+
+// multi types' columns
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, utf8}", {boolean(), 
utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int32}", {int32(), int32()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int64}", {int32(), int64()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{boolean, int64, utf8}",
+                  {boolean(), int64(), utf8()})
+    ->Apply(SetArgs);
+
+// multi types' columns with column resorted
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, boolean, utf8}",
+                  {int32(), boolean(), utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes, "{int32, int64, boolean, utf8}",
+                  {int32(), int64(), boolean(), utf8()})
+    ->Apply(SetArgs);
+BENCHMARK_CAPTURE(GrouperWithMultiTypes,
+                  "{utf8, int32, int64, fixed_size_binary(128), boolean}",
+                  {utf8(), int32(), int64(), fixed_size_binary(128), 
boolean()})
+    ->Apply(SetArgs);

Review Comment:
   My concern is that we don't want to grow the runtime of continuous 
benchmarking runs gratuitously, so benchmark variations like these should be 
motivated by a particular concern.



##########
cpp/src/arrow/compute/row/grouper_benchmark.cc:
##########
@@ -0,0 +1,127 @@
+// 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 "arrow/util/key_value_metadata.h"
+#include "arrow/util/string.h"
+#include "benchmark/benchmark.h"
+
+#include "arrow/compute/row/grouper.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/testing/random.h"
+#include "arrow/util/benchmark_util.h"
+
+namespace arrow {
+namespace compute {
+
+constexpr auto kSeed = 0x0ff1ce;
+constexpr int64_t kRound = 256;
+
+static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t 
num_rows,
+                                     double null_probability,
+                                     int64_t alignment = 
kDefaultBufferAlignment,
+                                     MemoryPool* memory_pool = nullptr) {
+  random::RandomArrayGenerator rng(kSeed);
+  auto num_types = static_cast<int>(types.size());
+
+  // clang-format off
+  auto metadata = key_value_metadata(
+      {
+        "null_probability",
+        "true_probability",
+        "unique"
+      },
+      {
+          internal::ToChars(null_probability),
+          internal::ToChars(null_probability),                     // for 
boolean type
+          internal::ToChars(static_cast<int32_t>(num_rows * 0.5))  // for 
string type
+      });

Review Comment:
   So, `int32` and `int64` keys will span the whole magnitude as well? Meaning 
they will be mostly unique?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to