Skip to content

Commit 61da64a

Browse files
authored
Extend aggregation benchmarks (#5096)
- Add benchmarks for float64 and integer types - Measure throughput - Increase batch size so that the final reduction step has less of an impact
1 parent dc75a28 commit 61da64a

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

arrow/benches/aggregate_kernels.rs

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,55 @@
1717

1818
#[macro_use]
1919
extern crate criterion;
20-
use criterion::Criterion;
20+
use criterion::{Criterion, Throughput};
21+
use rand::distributions::{Distribution, Standard};
2122

2223
extern crate arrow;
2324

2425
use arrow::compute::kernels::aggregate::*;
2526
use arrow::util::bench_util::*;
2627
use arrow::{array::*, datatypes::Float32Type};
28+
use arrow_array::types::{Float64Type, Int16Type, Int32Type, Int64Type, Int8Type};
2729

28-
fn bench_sum(arr_a: &Float32Array) {
29-
criterion::black_box(sum(arr_a).unwrap());
30-
}
31-
32-
fn bench_min(arr_a: &Float32Array) {
33-
criterion::black_box(min(arr_a).unwrap());
34-
}
35-
36-
fn bench_max(arr_a: &Float32Array) {
37-
criterion::black_box(max(arr_a).unwrap());
38-
}
30+
const BATCH_SIZE: usize = 64 * 1024;
3931

40-
fn bench_min_string(arr_a: &StringArray) {
41-
criterion::black_box(min_string(arr_a).unwrap());
32+
fn primitive_benchmark<T: ArrowNumericType>(c: &mut Criterion, name: &str)
33+
where
34+
Standard: Distribution<T::Native>,
35+
{
36+
let nonnull_array = create_primitive_array::<T>(BATCH_SIZE, 0.0);
37+
let nullable_array = create_primitive_array::<T>(BATCH_SIZE, 0.5);
38+
c.benchmark_group(name)
39+
.throughput(Throughput::Bytes(
40+
(std::mem::size_of::<T::Native>() * BATCH_SIZE) as u64,
41+
))
42+
.bench_function("sum nonnull", |b| b.iter(|| sum(&nonnull_array)))
43+
.bench_function("min nonnull", |b| b.iter(|| min(&nonnull_array)))
44+
.bench_function("max nonnull", |b| b.iter(|| max(&nonnull_array)))
45+
.bench_function("sum nullable", |b| b.iter(|| sum(&nullable_array)))
46+
.bench_function("min nullable", |b| b.iter(|| min(&nullable_array)))
47+
.bench_function("max nullable", |b| b.iter(|| max(&nullable_array)));
4248
}
4349

4450
fn add_benchmark(c: &mut Criterion) {
45-
let arr_a = create_primitive_array::<Float32Type>(512, 0.0);
46-
47-
c.bench_function("sum 512", |b| b.iter(|| bench_sum(&arr_a)));
48-
c.bench_function("min 512", |b| b.iter(|| bench_min(&arr_a)));
49-
c.bench_function("max 512", |b| b.iter(|| bench_max(&arr_a)));
50-
51-
let arr_a = create_primitive_array::<Float32Type>(512, 0.5);
52-
53-
c.bench_function("sum nulls 512", |b| b.iter(|| bench_sum(&arr_a)));
54-
c.bench_function("min nulls 512", |b| b.iter(|| bench_min(&arr_a)));
55-
c.bench_function("max nulls 512", |b| b.iter(|| bench_max(&arr_a)));
51+
primitive_benchmark::<Float32Type>(c, "float32");
52+
primitive_benchmark::<Float64Type>(c, "float64");
5653

57-
let arr_b = create_string_array::<i32>(512, 0.0);
58-
c.bench_function("min string 512", |b| b.iter(|| bench_min_string(&arr_b)));
54+
primitive_benchmark::<Int8Type>(c, "int8");
55+
primitive_benchmark::<Int16Type>(c, "int16");
56+
primitive_benchmark::<Int32Type>(c, "int32");
57+
primitive_benchmark::<Int64Type>(c, "int64");
5958

60-
let arr_b = create_string_array::<i32>(512, 0.5);
61-
c.bench_function("min nulls string 512", |b| {
62-
b.iter(|| bench_min_string(&arr_b))
63-
});
59+
{
60+
let nonnull_strings = create_string_array::<i32>(BATCH_SIZE, 0.0);
61+
let nullable_strings = create_string_array::<i32>(BATCH_SIZE, 0.5);
62+
c.benchmark_group("string")
63+
.throughput(Throughput::Elements(BATCH_SIZE as u64))
64+
.bench_function("min nonnull", |b| b.iter(|| min_string(&nonnull_strings)))
65+
.bench_function("max nonnull", |b| b.iter(|| max_string(&nonnull_strings)))
66+
.bench_function("min nullable", |b| b.iter(|| min_string(&nullable_strings)))
67+
.bench_function("max nullable", |b| b.iter(|| max_string(&nullable_strings)));
68+
}
6469
}
6570

6671
criterion_group!(benches, add_benchmark);

0 commit comments

Comments
 (0)