diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 142ae75c46c1..1910b6692f2c 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -697,6 +697,9 @@ if(ARROW_BUILD_BENCHMARKS) set(ARROW_BENCHMARK_LINK_LIBS benchmark::benchmark_main benchmark::benchmark ${ARROW_TEST_LINK_LIBS}) + if(WIN32) + set(ARROW_BENCHMARK_LINK_LIBS Shlwapi.dll ${ARROW_BENCHMARK_LINK_LIBS}) + endif() endif() set(ARROW_SYSTEM_LINK_LIBS) diff --git a/cpp/src/arrow/builder-benchmark.cc b/cpp/src/arrow/builder-benchmark.cc index bc36970f048f..e814c55e556b 100644 --- a/cpp/src/arrow/builder-benchmark.cc +++ b/cpp/src/arrow/builder-benchmark.cc @@ -160,7 +160,7 @@ static void BuildChunkedBinaryArray( static void BuildFixedSizeBinaryArray( benchmark::State& state) { // NOLINT non-const reference - auto type = fixed_size_binary(kBinaryView.size()); + auto type = fixed_size_binary(static_cast(kBinaryView.size())); for (auto _ : state) { FixedSizeBinaryBuilder builder(type); @@ -227,7 +227,8 @@ static std::vector MakeRandomIntDictFodder() { [&]() { return static_cast(values_dist(gen)); }); } { - std::uniform_int_distribution indices_dist(0, kDistinctElements - 1); + std::uniform_int_distribution indices_dist( + 0, static_cast(kDistinctElements - 1)); std::generate(values.begin(), values.end(), [&]() { return values_dict[indices_dist(gen)]; }); } @@ -262,7 +263,8 @@ static std::vector MakeStringDictFodder() { }); } { - std::uniform_int_distribution indices_dist(0, kDistinctElements - 1); + std::uniform_int_distribution indices_dist( + 0, static_cast(kDistinctElements - 1)); std::generate(values.begin(), values.end(), [&] { return values_dict[indices_dist(gen)]; }); } @@ -311,7 +313,7 @@ static void BuildStringDictionaryArray( benchmark::State& state) { // NOLINT non-const reference const auto fodder = MakeStringDictFodder(); auto fodder_size = - std::accumulate(fodder.begin(), fodder.end(), 0UL, + std::accumulate(fodder.begin(), fodder.end(), 0ULL, [&](size_t acc, const std::string& s) { return acc + s.size(); }); for (auto _ : state) { diff --git a/cpp/src/arrow/csv/parser-benchmark.cc b/cpp/src/arrow/csv/parser-benchmark.cc index c474af5c97a8..bb84f8eb59c9 100644 --- a/cpp/src/arrow/csv/parser-benchmark.cc +++ b/cpp/src/arrow/csv/parser-benchmark.cc @@ -33,11 +33,11 @@ namespace csv { const char* one_row = "abc,\"d,f\",12.34,\n"; const char* one_row_escaped = "abc,d\\,f,12.34,\n"; -size_t num_rows = (1024 * 64) / strlen(one_row); +const auto num_rows = static_cast((1024 * 64) / strlen(one_row)); -static std::string BuildCSVData(const std::string& row, size_t repeat) { +static std::string BuildCSVData(const std::string& row, int32_t repeat) { std::stringstream ss; - for (size_t i = 0; i < repeat; ++i) { + for (int32_t i = 0; i < repeat; ++i) { ss << row; } return ss.str(); diff --git a/cpp/src/arrow/util/bit-util-benchmark.cc b/cpp/src/arrow/util/bit-util-benchmark.cc index 5131ceb88d10..8725ad6c5ebe 100644 --- a/cpp/src/arrow/util/bit-util-benchmark.cc +++ b/cpp/src/arrow/util/bit-util-benchmark.cc @@ -124,6 +124,30 @@ static void BenchmarkBitmapReader(benchmark::State& state, int64_t nbytes) { state.SetBytesProcessed(2LL * state.iterations() * nbytes); } +template +static void BenchmarkVisitBits(benchmark::State& state, int64_t nbytes) { + std::shared_ptr buffer = CreateRandomBuffer(nbytes); + + const int64_t num_bits = nbytes * 8; + const uint8_t* bitmap = buffer->data(); + + for (auto _ : state) { + { + int64_t total = 0; + const auto visit = [&total](bool value) -> void { total += value; }; + VisitBitsFunctorType()(bitmap, 0, num_bits, visit); + benchmark::DoNotOptimize(total); + } + { + int64_t total = 0; + const auto visit = [&total](bool value) -> void { total += value; }; + VisitBitsFunctorType()(bitmap, 0, num_bits, visit); + benchmark::DoNotOptimize(total); + } + } + state.SetBytesProcessed(2LL * state.iterations() * nbytes); +} + constexpr bool pattern[] = {false, false, false, true, true, true}; static_assert( (sizeof(pattern) / sizeof(pattern[0])) % 8 != 0, @@ -204,6 +228,22 @@ struct GenerateBitsUnrolledFunctor { } }; +struct VisitBitsFunctor { + template + void operator()(const uint8_t* bitmap, int64_t start_offset, int64_t length, + Visitor&& g) { + return internal::VisitBits(bitmap, start_offset, length, g); + } +}; + +struct VisitBitsUnrolledFunctor { + template + void operator()(const uint8_t* bitmap, int64_t start_offset, int64_t length, + Visitor&& g) { + return internal::VisitBitsUnrolled(bitmap, start_offset, length, g); + } +}; + static void GenerateBits(benchmark::State& state) { BenchmarkGenerateBits(state, state.range(0)); } @@ -212,6 +252,14 @@ static void GenerateBitsUnrolled(benchmark::State& state) { BenchmarkGenerateBits(state, state.range(0)); } +static void VisitBits(benchmark::State& state) { + BenchmarkVisitBits(state, state.range(0)); +} + +static void VisitBitsUnrolled(benchmark::State& state) { + BenchmarkVisitBits(state, state.range(0)); +} + constexpr int64_t kBufferSize = 1024 * 8; template @@ -246,29 +294,32 @@ static void CopyBitmapWithOffset(benchmark::State& state) { // NOLINT non-const } #ifdef ARROW_WITH_BENCHMARKS_REFERENCE - static void ReferenceNaiveBitmapReader(benchmark::State& state) { BenchmarkBitmapReader(state, state.range(0)); } +BENCHMARK(ReferenceNaiveBitmapReader)->Arg(kBufferSize); +#endif + +BENCHMARK(BitmapReader)->Arg(kBufferSize); +BENCHMARK(VisitBits)->Arg(kBufferSize); +BENCHMARK(VisitBitsUnrolled)->Arg(kBufferSize); + +#ifdef ARROW_WITH_BENCHMARKS_REFERENCE static void ReferenceNaiveBitmapWriter(benchmark::State& state) { BenchmarkBitmapWriter(state, state.range(0)); } BENCHMARK(ReferenceNaiveBitmapWriter)->Arg(kBufferSize); -BENCHMARK(ReferenceNaiveBitmapReader)->Arg(kBufferSize); - #endif -BENCHMARK(CopyBitmapWithoutOffset)->Arg(kBufferSize); -BENCHMARK(CopyBitmapWithOffset)->Arg(kBufferSize); - -BENCHMARK(BitmapReader)->Arg(kBufferSize); BENCHMARK(BitmapWriter)->Arg(kBufferSize); - BENCHMARK(FirstTimeBitmapWriter)->Arg(kBufferSize); BENCHMARK(GenerateBits)->Arg(kBufferSize); BENCHMARK(GenerateBitsUnrolled)->Arg(kBufferSize); +BENCHMARK(CopyBitmapWithoutOffset)->Arg(kBufferSize); +BENCHMARK(CopyBitmapWithOffset)->Arg(kBufferSize); + } // namespace BitUtil } // namespace arrow diff --git a/cpp/src/arrow/util/hashing.h b/cpp/src/arrow/util/hashing.h index 1fc29a824521..49641d81c08d 100644 --- a/cpp/src/arrow/util/hashing.h +++ b/cpp/src/arrow/util/hashing.h @@ -716,10 +716,12 @@ class BinaryMemoTable : public MemoTable { int32_t left_offset = offsets_[start]; - // Ensure that the data_length is exactly missing width_size bytes to fit + // Ensure that the data length is exactly missing width_size bytes to fit // in the expected output (n_values * width_size). +#ifndef NDEBUG int64_t data_length = values_.size() - static_cast(left_offset); assert(data_length + width_size == out_size); +#endif auto in_data = values_.data() + left_offset; // The null use 0-length in the data, slice the data in 2 and skip by diff --git a/cpp/src/arrow/util/thread-pool-benchmark.cc b/cpp/src/arrow/util/thread-pool-benchmark.cc index b10a5d194dc5..25e040ba4f68 100644 --- a/cpp/src/arrow/util/thread-pool-benchmark.cc +++ b/cpp/src/arrow/util/thread-pool-benchmark.cc @@ -172,7 +172,7 @@ static void ThreadPoolSpawn_Customize(benchmark::internal::Benchmark* b) { // This benchmark simply provides a baseline indicating the raw cost of our workload // depending on the workload size. Number of items / second in this (serial) // benchmark can be compared to the numbers obtained in ThreadPoolSpawn. -static void WorkloadCost(benchmark::State& state) { +static void ReferenceWorkloadCost(benchmark::State& state) { const auto workload_size = static_cast(state.range(0)); Workload workload(workload_size);