Skip to content

Commit dcd00cf

Browse files
committed
Run boolean and bitwise kernels for longer to reduce noise
1 parent 389f404 commit dcd00cf

File tree

2 files changed

+105
-41
lines changed

2 files changed

+105
-41
lines changed

arrow/benches/bitwise_kernel.rs

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,80 +32,140 @@ extern crate arrow;
3232
use arrow::util::bench_util::create_primitive_array;
3333
use arrow::util::test_util::seedable_rng;
3434

35+
const ARRAY_LEN: usize = 8_192;
36+
37+
// These bitwise kernels are very cheap, so run them many times per Criterion iteration to
38+
// try and reduce noise in the benchmarks.
39+
const RUNS_PER_SAMPLE: usize = 100;
40+
3541
fn bitwise_array_benchmark(c: &mut Criterion) {
36-
let size = 64 * 1024_usize;
37-
let left_without_null = create_primitive_array::<Int64Type>(size, 0 as f32);
38-
let right_without_null = create_primitive_array::<Int64Type>(size, 0 as f32);
39-
let left_with_null = create_primitive_array::<Int64Type>(size, 0.2_f32);
40-
let right_with_null = create_primitive_array::<Int64Type>(size, 0.2_f32);
42+
let left_without_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0 as f32);
43+
let right_without_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0 as f32);
44+
let left_with_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0.2_f32);
45+
let right_with_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0.2_f32);
4146
// array and
4247
let mut group = c.benchmark_group("bench bitwise array: and");
4348
group.bench_function("bitwise array and, no nulls", |b| {
44-
b.iter(|| hint::black_box(bitwise_and(&left_without_null, &right_without_null).unwrap()))
49+
b.iter(|| {
50+
for _ in 0..RUNS_PER_SAMPLE {
51+
hint::black_box(bitwise_and(&left_without_null, &right_without_null).unwrap());
52+
}
53+
})
4554
});
4655
group.bench_function("bitwise array and, 20% nulls", |b| {
47-
b.iter(|| hint::black_box(bitwise_and(&left_with_null, &right_with_null).unwrap()))
56+
b.iter(|| {
57+
for _ in 0..RUNS_PER_SAMPLE {
58+
hint::black_box(bitwise_and(&left_with_null, &right_with_null).unwrap());
59+
}
60+
})
4861
});
4962
group.finish();
5063
// array or
5164
let mut group = c.benchmark_group("bench bitwise: or");
5265
group.bench_function("bitwise array or, no nulls", |b| {
53-
b.iter(|| hint::black_box(bitwise_or(&left_without_null, &right_without_null).unwrap()))
66+
b.iter(|| {
67+
for _ in 0..RUNS_PER_SAMPLE {
68+
hint::black_box(bitwise_or(&left_without_null, &right_without_null).unwrap());
69+
}
70+
})
5471
});
5572
group.bench_function("bitwise array or, 20% nulls", |b| {
56-
b.iter(|| hint::black_box(bitwise_or(&left_with_null, &right_with_null).unwrap()))
73+
b.iter(|| {
74+
for _ in 0..RUNS_PER_SAMPLE {
75+
hint::black_box(bitwise_or(&left_with_null, &right_with_null).unwrap());
76+
}
77+
})
5778
});
5879
group.finish();
5980
// xor
6081
let mut group = c.benchmark_group("bench bitwise: xor");
6182
group.bench_function("bitwise array xor, no nulls", |b| {
62-
b.iter(|| hint::black_box(bitwise_xor(&left_without_null, &right_without_null).unwrap()))
83+
b.iter(|| {
84+
for _ in 0..RUNS_PER_SAMPLE {
85+
hint::black_box(bitwise_xor(&left_without_null, &right_without_null).unwrap());
86+
}
87+
})
6388
});
6489
group.bench_function("bitwise array xor, 20% nulls", |b| {
65-
b.iter(|| hint::black_box(bitwise_xor(&left_with_null, &right_with_null).unwrap()))
90+
b.iter(|| {
91+
for _ in 0..RUNS_PER_SAMPLE {
92+
hint::black_box(bitwise_xor(&left_with_null, &right_with_null).unwrap());
93+
}
94+
})
6695
});
6796
group.finish();
6897
// not
6998
let mut group = c.benchmark_group("bench bitwise: not");
7099
group.bench_function("bitwise array not, no nulls", |b| {
71-
b.iter(|| hint::black_box(bitwise_not(&left_without_null).unwrap()))
100+
b.iter(|| {
101+
for _ in 0..RUNS_PER_SAMPLE {
102+
hint::black_box(bitwise_not(&left_without_null).unwrap());
103+
}
104+
});
72105
});
73106
group.bench_function("bitwise array not, 20% nulls", |b| {
74-
b.iter(|| hint::black_box(bitwise_not(&left_with_null).unwrap()))
107+
b.iter(|| {
108+
for _ in 0..RUNS_PER_SAMPLE {
109+
hint::black_box(bitwise_not(&left_with_null).unwrap());
110+
}
111+
});
75112
});
76113
group.finish();
77114
}
78115

79116
fn bitwise_array_scalar_benchmark(c: &mut Criterion) {
80-
let size = 64 * 1024_usize;
81-
let array_without_null = create_primitive_array::<Int64Type>(size, 0 as f32);
82-
let array_with_null = create_primitive_array::<Int64Type>(size, 0.2_f32);
117+
let array_without_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0 as f32);
118+
let array_with_null = create_primitive_array::<Int64Type>(ARRAY_LEN, 0.2_f32);
83119
let scalar = seedable_rng().next_u64() as i64;
84120
// array scalar and
85121
let mut group = c.benchmark_group("bench bitwise array scalar: and");
86122
group.bench_function("bitwise array scalar and, no nulls", |b| {
87-
b.iter(|| hint::black_box(bitwise_and_scalar(&array_without_null, scalar).unwrap()))
123+
b.iter(|| {
124+
for _ in 0..RUNS_PER_SAMPLE {
125+
hint::black_box(bitwise_and_scalar(&array_without_null, scalar).unwrap());
126+
}
127+
})
88128
});
89129
group.bench_function("bitwise array and, 20% nulls", |b| {
90-
b.iter(|| hint::black_box(bitwise_and_scalar(&array_with_null, scalar).unwrap()))
130+
b.iter(|| {
131+
for _ in 0..RUNS_PER_SAMPLE {
132+
hint::black_box(bitwise_and_scalar(&array_with_null, scalar).unwrap());
133+
}
134+
})
91135
});
92136
group.finish();
93137
// array scalar or
94138
let mut group = c.benchmark_group("bench bitwise array scalar: or");
95139
group.bench_function("bitwise array scalar or, no nulls", |b| {
96-
b.iter(|| hint::black_box(bitwise_or_scalar(&array_without_null, scalar).unwrap()))
140+
b.iter(|| {
141+
for _ in 0..RUNS_PER_SAMPLE {
142+
hint::black_box(bitwise_or_scalar(&array_without_null, scalar).unwrap());
143+
}
144+
})
97145
});
98146
group.bench_function("bitwise array scalar or, 20% nulls", |b| {
99-
b.iter(|| hint::black_box(bitwise_or_scalar(&array_with_null, scalar).unwrap()))
147+
b.iter(|| {
148+
for _ in 0..RUNS_PER_SAMPLE {
149+
hint::black_box(bitwise_or_scalar(&array_with_null, scalar).unwrap());
150+
}
151+
})
100152
});
101153
group.finish();
102154
// array scalar xor
103155
let mut group = c.benchmark_group("bench bitwise array scalar: xor");
104156
group.bench_function("bitwise array scalar xor, no nulls", |b| {
105-
b.iter(|| hint::black_box(bitwise_xor_scalar(&array_without_null, scalar).unwrap()))
157+
b.iter(|| {
158+
for _ in 0..RUNS_PER_SAMPLE {
159+
hint::black_box(bitwise_xor_scalar(&array_without_null, scalar).unwrap());
160+
}
161+
})
106162
});
107163
group.bench_function("bitwise array scalar xor, 20% nulls", |b| {
108-
b.iter(|| hint::black_box(bitwise_xor_scalar(&array_with_null, scalar).unwrap()))
164+
b.iter(|| {
165+
for _ in 0..RUNS_PER_SAMPLE {
166+
hint::black_box(bitwise_xor_scalar(&array_with_null, scalar).unwrap());
167+
}
168+
})
109169
});
110170
group.finish();
111171
}

arrow/benches/boolean_kernels.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,48 @@ use arrow::array::*;
2727
use arrow::compute::kernels::boolean as boolean_kernels;
2828
use std::hint;
2929

30+
const ARRAY_LEN: usize = 8_192;
31+
// These bitwise kernels are very cheap, so run them many times per Criterion iteration to
32+
// try and reduce noise in the benchmarks.
33+
const RUNS_PER_SAMPLE: usize = 100;
34+
3035
fn bench_and(lhs: &BooleanArray, rhs: &BooleanArray) {
31-
hint::black_box(boolean_kernels::and(lhs, rhs).unwrap());
36+
for _ in 0..RUNS_PER_SAMPLE {
37+
hint::black_box(boolean_kernels::and(lhs, rhs).unwrap());
38+
}
3239
}
3340

3441
fn bench_or(lhs: &BooleanArray, rhs: &BooleanArray) {
35-
hint::black_box(boolean_kernels::or(lhs, rhs).unwrap());
42+
for _ in 0..RUNS_PER_SAMPLE {
43+
hint::black_box(boolean_kernels::or(lhs, rhs).unwrap());
44+
}
3645
}
3746

3847
fn bench_not(array: &BooleanArray) {
39-
hint::black_box(boolean_kernels::not(array).unwrap());
48+
for _ in 0..RUNS_PER_SAMPLE {
49+
hint::black_box(boolean_kernels::not(array).unwrap());
50+
}
4051
}
4152

4253
fn add_benchmark(c: &mut Criterion) {
43-
let size = 2usize.pow(15);
44-
let array1 = create_boolean_array(size, 0.0, 0.5);
45-
let array2 = create_boolean_array(size, 0.0, 0.5);
54+
let array1_full = create_boolean_array(ARRAY_LEN + 1, 0.0, 0.5);
55+
let array2_full = create_boolean_array(ARRAY_LEN + 1, 0.0, 0.5);
56+
let array1 = array1_full.slice(0, ARRAY_LEN);
57+
let array2 = array2_full.slice(0, ARRAY_LEN);
4658
c.bench_function("and", |b| b.iter(|| bench_and(&array1, &array2)));
4759
c.bench_function("or", |b| b.iter(|| bench_or(&array1, &array2)));
4860
c.bench_function("not", |b| b.iter(|| bench_not(&array1)));
4961

50-
let array1_slice = array1.slice(1, size - 1);
51-
let array1_slice = array1_slice
52-
.as_any()
53-
.downcast_ref::<BooleanArray>()
54-
.unwrap();
55-
let array2_slice = array2.slice(1, size - 1);
56-
let array2_slice = array2_slice
57-
.as_any()
58-
.downcast_ref::<BooleanArray>()
59-
.unwrap();
62+
let array1_slice = array1_full.slice(1, ARRAY_LEN);
63+
let array2_slice = array2_full.slice(1, ARRAY_LEN);
6064

6165
c.bench_function("and_sliced", |b| {
62-
b.iter(|| bench_and(array1_slice, array2_slice))
66+
b.iter(|| bench_and(&array1_slice, &array2_slice))
6367
});
6468
c.bench_function("or_sliced", |b| {
65-
b.iter(|| bench_or(array1_slice, array2_slice))
69+
b.iter(|| bench_or(&array1_slice, &array2_slice))
6670
});
67-
c.bench_function("not_sliced", |b| b.iter(|| bench_not(array1_slice)));
71+
c.bench_function("not_sliced", |b| b.iter(|| bench_not(&array1_slice)));
6872
}
6973

7074
criterion_group!(benches, add_benchmark);

0 commit comments

Comments
 (0)