Copilot commented on code in PR #45001: URL: https://github.com/apache/arrow/pull/45001#discussion_r3645011320
########## cpp/src/arrow/compute/kernels/scalar_hash_benchmark.cc: ########## @@ -0,0 +1,235 @@ +// 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 <algorithm> +#include <cstdint> +#include <limits> +#include <random> +#include <string> +#include <vector> + +#include "benchmark/benchmark.h" + +#include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" +#include "arrow/util/hashing.h" + +#include "arrow/array/array_nested.h" +#include "arrow/compute/exec.h" + +namespace arrow { +namespace internal { + +// ------------------------------ +// Anonymous namespace with global params + +namespace { +// copied from scalar_string_benchmark +constexpr auto kSeed = 0x94378165; +constexpr double null_prob = 0.2; + +static random::RandomArrayGenerator hashing_rng(kSeed); +} // namespace + +// ------------------------------ +// Convenience functions + +static Result<std::shared_ptr<StructArray>> MakeStructArray(int64_t n_values, + int32_t min_strlen, + int32_t max_strlen) { + auto vals_first = hashing_rng.Int64(n_values, 0, std::numeric_limits<int64_t>::max()); + auto vals_second = hashing_rng.String(n_values, min_strlen, max_strlen, null_prob); + auto vals_third = hashing_rng.Int64(n_values, 0, std::numeric_limits<int64_t>::max()); + + return arrow::StructArray::Make( + arrow::ArrayVector{vals_first, vals_second, vals_third}, + arrow::FieldVector{arrow::field("first", arrow::int64()), + arrow::field("second", arrow::utf8()), + arrow::field("third", arrow::int64())}); +} + +// ------------------------------ +// Benchmark implementations + +static void Hash64Int64(benchmark::State& state) { // NOLINT non-const reference + auto test_vals = hashing_rng.Int64(10000, 0, std::numeric_limits<int64_t>::max()); + + while (state.KeepRunning()) { + ASSERT_OK_AND_ASSIGN(Datum hash_result, compute::CallFunction("hash64", {test_vals})); + benchmark::DoNotOptimize(hash_result); + } Review Comment: This benchmark uses `ASSERT_OK_AND_ASSIGN` inside the hot `while (state.KeepRunning())` loop. The gtest assertion machinery can add measurable overhead and distort timings; other Arrow benchmarks typically use `ValueOrDie()` / `ARROW_CHECK_OK`-style checks instead. Consider switching the in-loop call sites to `compute::CallFunction(...).ValueOrDie()` (and applying the same change to the other loops in this file). -- 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]
