Skip to content

Commit

Permalink
Make bool_or an alias for max_boolean (#6100)
Browse files Browse the repository at this point in the history
Improves `cargo bench --bench aggregate_kernels -- "bool/or"` throughput by 68%-22366% on my machine
  • Loading branch information
simonvandel authored Jul 23, 2024
1 parent 658e58f commit 8aa91e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 1 addition & 4 deletions arrow-arith/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ pub fn bool_and(array: &BooleanArray) -> Option<bool> {
///
/// Returns `None` if the array is empty or only contains null values.
pub fn bool_or(array: &BooleanArray) -> Option<bool> {
if array.null_count() == array.len() {
return None;
}
Some(array.true_count() != 0)
max_boolean(array)
}

/// Returns the sum of values in the primitive array.
Expand Down
18 changes: 18 additions & 0 deletions arrow/benches/aggregate_kernels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,53 @@ fn add_benchmark(c: &mut Criterion) {
.bench_function("max nonnull mixed", |b| {
b.iter(|| max_boolean(&nonnull_bools_mixed))
})
.bench_function("or nonnull mixed", |b| {
b.iter(|| bool_or(&nonnull_bools_mixed))
})
.bench_function("min nonnull false", |b| {
b.iter(|| min_boolean(&nonnull_bools_all_false))
})
.bench_function("max nonnull false", |b| {
b.iter(|| max_boolean(&nonnull_bools_all_false))
})
.bench_function("or nonnull false", |b| {
b.iter(|| bool_or(&nonnull_bools_all_false))
})
.bench_function("min nonnull true", |b| {
b.iter(|| min_boolean(&nonnull_bools_all_true))
})
.bench_function("max nonnull true", |b| {
b.iter(|| max_boolean(&nonnull_bools_all_true))
})
.bench_function("or nonnull true", |b| {
b.iter(|| bool_or(&nonnull_bools_all_true))
})
.bench_function("min nullable mixed", |b| {
b.iter(|| min_boolean(&nullable_bool_mixed))
})
.bench_function("max nullable mixed", |b| {
b.iter(|| max_boolean(&nullable_bool_mixed))
})
.bench_function("or nullable mixed", |b| {
b.iter(|| bool_or(&nullable_bool_mixed))
})
.bench_function("min nullable false", |b| {
b.iter(|| min_boolean(&nullable_bool_all_false))
})
.bench_function("max nullable false", |b| {
b.iter(|| max_boolean(&nullable_bool_all_false))
})
.bench_function("or nullable false", |b| {
b.iter(|| bool_or(&nullable_bool_all_false))
})
.bench_function("min nullable true", |b| {
b.iter(|| min_boolean(&nullable_bool_all_true))
})
.bench_function("max nullable true", |b| {
b.iter(|| max_boolean(&nullable_bool_all_true))
})
.bench_function("or nullable true", |b| {
b.iter(|| bool_or(&nullable_bool_all_true))
});
}
}
Expand Down

0 comments on commit 8aa91e5

Please sign in to comment.