Skip to content

Commit 9f1e1c9

Browse files
committed
bench(arrow): add dictionary cases to merge_kernels, including one that merges dictionaries
1 parent 4253beb commit 9f1e1c9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎arrow/benches/merge_kernels.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,36 @@ fn bench_merge_input_on_all_masks(
225225
}
226226
}
227227

228+
/// An Int8-keyed dictionary of `len` random keys into `distinct` string values.
229+
/// Each call builds its own values array, so two calls share values but not
230+
/// the dictionary itself
231+
fn generate_int8_dictionary(seed: u64, len: usize, distinct: usize) -> ArrayRef {
232+
let mut rng = StdRng::seed_from_u64(seed);
233+
let values = StringArray::from_iter_values((0..distinct).map(|i| format!("value_{i}")));
234+
let keys = Int8Array::from_iter_values((0..len).map(|_| rng.random_range(0..distinct) as i8));
235+
Arc::new(DictionaryArray::<Int8Type>::try_new(keys, Arc::new(values)).unwrap())
236+
}
237+
238+
fn bench_merge_dictionaries(c: &mut Criterion) {
239+
const ARRAY_LEN: usize = 8192;
240+
241+
let mut group = c.benchmark_group(format!("merge_{ARRAY_LEN}_from_int8_dictionaries"));
242+
let masks = mask_cases(ARRAY_LEN);
243+
244+
// 2 x 50 values fit in Int8 keys when the dictionaries are concatenated,
245+
// 2 x 100 values do not, so merging them has to merge the dictionaries
246+
for (description, distinct) in [
247+
("array_vs_array_concatenated_values_fit", 50),
248+
("array_vs_array_concatenated_values_overflow", 100),
249+
] {
250+
let truthy = generate_int8_dictionary(42, ARRAY_LEN, distinct);
251+
let falsy = generate_int8_dictionary(18, ARRAY_LEN, distinct);
252+
bench_merge_input_on_all_masks(description, &mut group, &masks, &truthy, &falsy);
253+
}
254+
255+
group.finish();
256+
}
257+
228258
fn add_benchmark(c: &mut Criterion) {
229259
// Primitive
230260
bench_merge_on_input_generator(
@@ -274,6 +304,9 @@ fn add_benchmark(c: &mut Criterion) {
274304
_marker: std::marker::PhantomData,
275305
},
276306
);
307+
308+
// Dictionaries
309+
bench_merge_dictionaries(c);
277310
}
278311

279312
criterion_group!(benches, add_benchmark);

0 commit comments

Comments
 (0)