Skip to content

Commit c10547a

Browse files
committed
apacheGH-39663: [C++] Ensure top-level benchmarks present informative metrics
Add bytes/second and/or items/second metrics where applicable.
1 parent 2422994 commit c10547a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

cpp/src/arrow/builder_benchmark.cc

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ constexpr int64_t kRounds = 256;
5656
static VectorType kData = AlmostU8CompressibleVector();
5757
constexpr int64_t kBytesProcessPerRound = kNumberOfElements * sizeof(ValueType);
5858
constexpr int64_t kBytesProcessed = kRounds * kBytesProcessPerRound;
59+
constexpr int64_t kItemsProcessed = kRounds * kNumberOfElements;
5960

6061
static const char* kBinaryString = "12345678";
6162
static std::string_view kBinaryView(kBinaryString);
@@ -73,6 +74,7 @@ static void BuildIntArrayNoNulls(benchmark::State& state) { // NOLINT non-const
7374
}
7475

7576
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
77+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
7678
}
7779

7880
static void BuildAdaptiveIntNoNulls(
@@ -89,6 +91,7 @@ static void BuildAdaptiveIntNoNulls(
8991
}
9092

9193
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
94+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
9295
}
9396

9497
static void BuildAdaptiveIntNoNullsScalarAppend(
@@ -107,6 +110,7 @@ static void BuildAdaptiveIntNoNullsScalarAppend(
107110
}
108111

109112
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
113+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
110114
}
111115

112116
static void BuildBooleanArrayNoNulls(
@@ -127,6 +131,7 @@ static void BuildBooleanArrayNoNulls(
127131
}
128132

129133
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
134+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
130135
}
131136

132137
static void BuildBinaryArray(benchmark::State& state) { // NOLINT non-const reference
@@ -142,6 +147,7 @@ static void BuildBinaryArray(benchmark::State& state) { // NOLINT non-const ref
142147
}
143148

144149
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
150+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
145151
}
146152

147153
static void BuildChunkedBinaryArray(
@@ -161,6 +167,7 @@ static void BuildChunkedBinaryArray(
161167
}
162168

163169
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
170+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
164171
}
165172

166173
static void BuildFixedSizeBinaryArray(
@@ -179,6 +186,7 @@ static void BuildFixedSizeBinaryArray(
179186
}
180187

181188
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
189+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
182190
}
183191

184192
static void BuildDecimalArray(benchmark::State& state) { // NOLINT non-const reference
@@ -199,6 +207,7 @@ static void BuildDecimalArray(benchmark::State& state) { // NOLINT non-const re
199207
}
200208

201209
state.SetBytesProcessed(state.iterations() * kRounds * kNumberOfElements * 16);
210+
state.SetItemsProcessed(state.iterations() * kRounds * kNumberOfElements);
202211
}
203212

204213
// ----------------------------------------------------------------------
@@ -317,6 +326,7 @@ static void BenchmarkDictionaryArray(
317326
fodder_nbytes = fodder.size() * sizeof(Scalar);
318327
}
319328
state.SetBytesProcessed(state.iterations() * fodder_nbytes * kRounds);
329+
state.SetItemsProcessed(state.iterations() * fodder.size() * kRounds);
320330
}
321331

322332
static void BuildInt64DictionaryArrayRandom(
@@ -361,6 +371,7 @@ static void ArrayDataConstructDestruct(
361371
InitArrays();
362372
arrays.clear();
363373
}
374+
state.SetItemsProcessed(state.iterations() * kNumArrays);
364375
}
365376

366377
// ----------------------------------------------------------------------
@@ -430,6 +441,7 @@ static void ReferenceBuildVectorNoNulls(
430441
}
431442

432443
state.SetBytesProcessed(state.iterations() * kBytesProcessed);
444+
state.SetItemsProcessed(state.iterations() * kItemsProcessed);
433445
}
434446

435447
BENCHMARK(ReferenceBuildVectorNoNulls);

cpp/src/arrow/memory_pool_benchmark.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace arrow {
2525

26+
static constexpr int64_t kCacheLineSize = 64;
27+
2628
struct SystemAlloc {
2729
static Result<MemoryPool*> GetAllocator() { return system_memory_pool(); }
2830
};
@@ -51,8 +53,8 @@ static void TouchCacheLines(uint8_t* data, int64_t nbytes) {
5153
uint8_t total = 0;
5254
while (nbytes > 0) {
5355
total += *data;
54-
data += 64;
55-
nbytes -= 64;
56+
data += kCacheLineSize;
57+
nbytes -= kCacheLineSize;
5658
}
5759
benchmark::DoNotOptimize(total);
5860
}
@@ -71,6 +73,8 @@ static void TouchArea(benchmark::State& state) { // NOLINT non-const reference
7173
}
7274

7375
pool->Free(data, nbytes);
76+
state.SetItemsProcessed(state.iterations());
77+
state.SetBytesProcessed(state.iterations() * nbytes);
7478
}
7579

7680
// Benchmark the raw cost of allocating memory.
@@ -88,6 +92,9 @@ static void AllocateDeallocate(benchmark::State& state) { // NOLINT non-const r
8892
ARROW_CHECK_OK(pool->Allocate(nbytes, &data));
8993
pool->Free(data, nbytes);
9094
}
95+
state.SetItemsProcessed(state.iterations());
96+
// SetBytesProcessed() would give nonsensical figures since the data is not
97+
// actually processed.
9198
}
9299

93100
// Benchmark the cost of allocating memory plus accessing it.
@@ -103,6 +110,8 @@ static void AllocateTouchDeallocate(
103110
TouchCacheLines(data, nbytes);
104111
pool->Free(data, nbytes);
105112
}
113+
state.SetItemsProcessed(state.iterations());
114+
state.SetBytesProcessed(state.iterations() * nbytes);
106115
}
107116

108117
#define BENCHMARK_ALLOCATE_ARGS \

cpp/src/arrow/util/int_util_benchmark.cc

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static void DetectUIntWidthNoNulls(
6464
benchmark::DoNotOptimize(result);
6565
}
6666
state.SetBytesProcessed(state.iterations() * values.size() * sizeof(uint64_t));
67+
state.SetItemsProcessed(state.iterations() * values.size());
6768
}
6869

6970
static void DetectUIntWidthNulls(benchmark::State& state) { // NOLINT non-const reference
@@ -76,6 +77,7 @@ static void DetectUIntWidthNulls(benchmark::State& state) { // NOLINT non-const
7677
benchmark::DoNotOptimize(result);
7778
}
7879
state.SetBytesProcessed(state.iterations() * values.size() * sizeof(uint64_t));
80+
state.SetItemsProcessed(state.iterations() * values.size());
7981
}
8082

8183
static void DetectIntWidthNoNulls(
@@ -87,6 +89,7 @@ static void DetectIntWidthNoNulls(
8789
benchmark::DoNotOptimize(result);
8890
}
8991
state.SetBytesProcessed(state.iterations() * values.size() * sizeof(uint64_t));
92+
state.SetItemsProcessed(state.iterations() * values.size());
9093
}
9194

9295
static void DetectIntWidthNulls(benchmark::State& state) { // NOLINT non-const reference
@@ -99,6 +102,7 @@ static void DetectIntWidthNulls(benchmark::State& state) { // NOLINT non-const
99102
benchmark::DoNotOptimize(result);
100103
}
101104
state.SetBytesProcessed(state.iterations() * values.size() * sizeof(uint64_t));
105+
state.SetItemsProcessed(state.iterations() * values.size());
102106
}
103107

104108
static void CheckIndexBoundsInt32(

cpp/src/arrow/util/range_benchmark.cc

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void for_loop(benchmark::State& state) {
4646
for (auto _ : state) {
4747
for (int64_t index = 0; index < kSize; ++index) target[index] = source[index] + 1;
4848
}
49+
state.SetItemsProcessed(state.iterations() * kSize);
4950
}
5051

5152
BENCHMARK(for_loop);
@@ -58,6 +59,7 @@ void std_copy(benchmark::State& state) {
5859
for (auto _ : state) {
5960
std::copy(source.begin(), source.end(), target.begin());
6061
}
62+
state.SetItemsProcessed(state.iterations() * kSize);
6163
}
6264

6365
BENCHMARK(std_copy);
@@ -71,6 +73,7 @@ void std_copy_converting(benchmark::State& state) {
7173
for (auto _ : state) {
7274
std::copy(source.begin(), source.end(), target.begin());
7375
}
76+
state.SetItemsProcessed(state.iterations() * kSize);
7477
}
7578

7679
BENCHMARK(std_copy_converting);
@@ -85,6 +88,7 @@ void lazy_copy(benchmark::State& state) {
8588
for (auto _ : state) {
8689
std::copy(lazy_range.begin(), lazy_range.end(), target.begin());
8790
}
91+
state.SetItemsProcessed(state.iterations() * kSize);
8892
}
8993

9094
BENCHMARK(lazy_copy);
@@ -101,6 +105,7 @@ void lazy_copy_converting(benchmark::State& state) {
101105
for (auto _ : state) {
102106
std::copy(lazy_range.begin(), lazy_range.end(), target.begin());
103107
}
108+
state.SetItemsProcessed(state.iterations() * kSize);
104109
}
105110

106111
BENCHMARK(lazy_copy_converting);
@@ -119,6 +124,7 @@ void lazy_postinc(benchmark::State& state) {
119124

120125
while (lazy_iter != lazy_end) *(target_iter++) = *(lazy_iter++);
121126
}
127+
state.SetItemsProcessed(state.iterations() * kSize);
122128
}
123129

124130
BENCHMARK(lazy_postinc);

0 commit comments

Comments
 (0)