Skip to content

Commit f338149

Browse files
authored
Add nullif_kernel benchmark (#9089)
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - related to #9085 - related to #9022 # Rationale for this change the `nullif` kernel has an optimization for counting nulls as part of applying nullif, and I did not know if that made a difference (turns out it does). I made a benchmark to be able to measure this difference # What changes are included in this PR? Add a `nullif_kernel` benchmark # Are these changes tested? I ran them manually # Are there any user-facing changes? No new benchmark
1 parent 6aae76b commit f338149

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

arrow/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ name = "coalesce_kernels"
172172
harness = false
173173
required-features = ["test_utils"]
174174

175-
176175
[[bench]]
177176
name = "take_kernels"
178177
harness = false
@@ -311,6 +310,11 @@ name = "lexsort"
311310
harness = false
312311
required-features = ["test_utils"]
313312

313+
[[bench]]
314+
name = "nullif_kernel"
315+
harness = false
316+
required-features = ["test_utils"]
317+
314318
[[test]]
315319
name = "csv"
316320
required-features = ["csv", "chrono-tz"]

arrow/benches/nullif_kernel.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#[macro_use]
19+
extern crate criterion;
20+
use criterion::Criterion;
21+
22+
use arrow::util::bench_util::{create_boolean_array, create_primitive_array};
23+
24+
use arrow::array::*;
25+
use arrow_array::types::Int64Type;
26+
use arrow_select::nullif::nullif;
27+
use std::hint;
28+
29+
fn bench_nullif(left: &dyn Array, right: &BooleanArray) {
30+
hint::black_box(nullif(left, right).unwrap());
31+
}
32+
33+
fn add_benchmark(c: &mut Criterion) {
34+
let size = 8192usize;
35+
36+
// create input before benchmark to ensure allocations are consistent
37+
let int64_no_nulls = create_primitive_array::<Int64Type>(size, 0.0);
38+
let int64_nulls = create_primitive_array::<Int64Type>(size, 0.1);
39+
40+
let mask_10 = create_boolean_array(size, 0.0, 0.1);
41+
let mask_10_sliced = create_boolean_array(size + 7, 0.0, 0.1).slice(7, size);
42+
let mask_1 = create_boolean_array(size, 0.0, 0.01);
43+
44+
c.bench_function("nullif no-nulls mask(10%)", |b| {
45+
b.iter(|| bench_nullif(&int64_no_nulls, &mask_10))
46+
});
47+
c.bench_function("nullif no-nulls mask(10%, sliced)", |b| {
48+
b.iter(|| bench_nullif(&int64_no_nulls, &mask_10_sliced))
49+
});
50+
c.bench_function("nullif no-nulls mask(1%)", |b| {
51+
b.iter(|| bench_nullif(&int64_no_nulls, &mask_1))
52+
});
53+
54+
c.bench_function("nullif nulls mask(10%)", |b| {
55+
b.iter(|| bench_nullif(&int64_nulls, &mask_10))
56+
});
57+
c.bench_function("nullif nulls mask(10%, sliced)", |b| {
58+
b.iter(|| bench_nullif(&int64_nulls, &mask_10_sliced))
59+
});
60+
c.bench_function("nullif nulls mask(1%)", |b| {
61+
b.iter(|| bench_nullif(&int64_nulls, &mask_1))
62+
});
63+
}
64+
65+
criterion_group!(benches, add_benchmark);
66+
criterion_main!(benches);

0 commit comments

Comments
 (0)