|
17 | 17 |
|
18 | 18 | #[macro_use] |
19 | 19 | extern crate criterion; |
20 | | -use criterion::Criterion; |
| 20 | +use criterion::{Criterion, Throughput}; |
| 21 | +use rand::distributions::{Distribution, Standard}; |
21 | 22 |
|
22 | 23 | extern crate arrow; |
23 | 24 |
|
24 | 25 | use arrow::compute::kernels::aggregate::*; |
25 | 26 | use arrow::util::bench_util::*; |
26 | 27 | use arrow::{array::*, datatypes::Float32Type}; |
| 28 | +use arrow_array::types::{Float64Type, Int16Type, Int32Type, Int64Type, Int8Type}; |
27 | 29 |
|
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; |
39 | 31 |
|
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))); |
42 | 48 | } |
43 | 49 |
|
44 | 50 | 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"); |
56 | 53 |
|
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"); |
59 | 58 |
|
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 | + } |
64 | 69 | } |
65 | 70 |
|
66 | 71 | criterion_group!(benches, add_benchmark); |
|
0 commit comments