Skip to content

Commit e8fe907

Browse files
committed
bitmap_smaller_datatypes
1 parent f03c0d0 commit e8fe907

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

datafusion/functions-aggregate/benches/approx_distinct.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use std::sync::Arc;
1919

2020
use arrow::array::{
21-
ArrayRef, Int8Array, Int16Array, Int64Array, StringArray, StringViewArray,
22-
UInt8Array, UInt16Array,
21+
ArrayRef, BooleanArray, Int8Array, Int16Array, Int64Array, StringArray,
22+
StringViewArray, UInt8Array, UInt16Array,
2323
};
2424
use arrow::datatypes::{DataType, Field, Schema};
2525
use criterion::{Criterion, criterion_group, criterion_main};
@@ -91,6 +91,13 @@ fn create_i16_array(n_distinct: usize) -> Int16Array {
9191
.collect()
9292
}
9393

94+
fn create_bool_array() -> BooleanArray {
95+
let mut rng = StdRng::seed_from_u64(42);
96+
(0..BATCH_SIZE)
97+
.map(|_| Some(rng.random_bool(0.5)))
98+
.collect()
99+
}
100+
94101
/// Creates a pool of `n_distinct` random strings of the given length.
95102
fn create_string_pool(n_distinct: usize, string_length: usize) -> Vec<String> {
96103
let mut rng = StdRng::seed_from_u64(42);
@@ -169,7 +176,7 @@ fn approx_distinct_benchmark(c: &mut Criterion) {
169176
}
170177
}
171178

172-
// Small integer types
179+
// --- Bitmap type benchmarks (our optimization) ---
173180

174181
// UInt8
175182
let values = Arc::new(create_u8_array(200)) as ArrayRef;
@@ -214,6 +221,17 @@ fn approx_distinct_benchmark(c: &mut Criterion) {
214221
.unwrap()
215222
})
216223
});
224+
225+
// Boolean
226+
let values = Arc::new(create_bool_array()) as ArrayRef;
227+
c.bench_function("approx_distinct bool bitmap", |b| {
228+
b.iter(|| {
229+
let mut accumulator = prepare_accumulator(DataType::Boolean);
230+
accumulator
231+
.update_batch(std::slice::from_ref(&values))
232+
.unwrap()
233+
})
234+
});
217235
}
218236

219237
criterion_group!(benches, approx_distinct_benchmark);

0 commit comments

Comments
 (0)