This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new f3381492af Add nullif_kernel benchmark (#9089)
f3381492af is described below

commit f3381492afc90d763fd80e4044e37e52d4b3a5e2
Author: Andrew Lamb <[email protected]>
AuthorDate: Sun Jan 11 07:02:46 2026 -0500

    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 https://github.com/apache/arrow-rs/issues/9085
    - related to https://github.com/apache/arrow-rs/pull/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
---
 arrow/Cargo.toml               |  6 +++-
 arrow/benches/nullif_kernel.rs | 66 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml
index 4200cd7a6c..0c5a925ae3 100644
--- a/arrow/Cargo.toml
+++ b/arrow/Cargo.toml
@@ -172,7 +172,6 @@ name = "coalesce_kernels"
 harness = false
 required-features = ["test_utils"]
 
-
 [[bench]]
 name = "take_kernels"
 harness = false
@@ -311,6 +310,11 @@ name = "lexsort"
 harness = false
 required-features = ["test_utils"]
 
+[[bench]]
+name = "nullif_kernel"
+harness = false
+required-features = ["test_utils"]
+
 [[test]]
 name = "csv"
 required-features = ["csv", "chrono-tz"]
diff --git a/arrow/benches/nullif_kernel.rs b/arrow/benches/nullif_kernel.rs
new file mode 100644
index 0000000000..61ae7d4eea
--- /dev/null
+++ b/arrow/benches/nullif_kernel.rs
@@ -0,0 +1,66 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#[macro_use]
+extern crate criterion;
+use criterion::Criterion;
+
+use arrow::util::bench_util::{create_boolean_array, create_primitive_array};
+
+use arrow::array::*;
+use arrow_array::types::Int64Type;
+use arrow_select::nullif::nullif;
+use std::hint;
+
+fn bench_nullif(left: &dyn Array, right: &BooleanArray) {
+    hint::black_box(nullif(left, right).unwrap());
+}
+
+fn add_benchmark(c: &mut Criterion) {
+    let size = 8192usize;
+
+    // create input before benchmark to ensure allocations are consistent
+    let int64_no_nulls = create_primitive_array::<Int64Type>(size, 0.0);
+    let int64_nulls = create_primitive_array::<Int64Type>(size, 0.1);
+
+    let mask_10 = create_boolean_array(size, 0.0, 0.1);
+    let mask_10_sliced = create_boolean_array(size + 7, 0.0, 0.1).slice(7, 
size);
+    let mask_1 = create_boolean_array(size, 0.0, 0.01);
+
+    c.bench_function("nullif no-nulls mask(10%)", |b| {
+        b.iter(|| bench_nullif(&int64_no_nulls, &mask_10))
+    });
+    c.bench_function("nullif no-nulls mask(10%, sliced)", |b| {
+        b.iter(|| bench_nullif(&int64_no_nulls, &mask_10_sliced))
+    });
+    c.bench_function("nullif no-nulls mask(1%)", |b| {
+        b.iter(|| bench_nullif(&int64_no_nulls, &mask_1))
+    });
+
+    c.bench_function("nullif nulls mask(10%)", |b| {
+        b.iter(|| bench_nullif(&int64_nulls, &mask_10))
+    });
+    c.bench_function("nullif nulls mask(10%, sliced)", |b| {
+        b.iter(|| bench_nullif(&int64_nulls, &mask_10_sliced))
+    });
+    c.bench_function("nullif nulls mask(1%)", |b| {
+        b.iter(|| bench_nullif(&int64_nulls, &mask_1))
+    });
+}
+
+criterion_group!(benches, add_benchmark);
+criterion_main!(benches);

Reply via email to