From 18ee868032dbf562d755c65ad5af8322307bcc3b Mon Sep 17 00:00:00 2001 From: Adam Gutglick Date: Mon, 30 Mar 2026 12:24:30 +0100 Subject: [PATCH] Add List and ListView take benchmarks --- arrow/benches/take_kernels.rs | 60 ++++++++++++++++++++++++++++ arrow/src/util/bench_util.rs | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/arrow/benches/take_kernels.rs b/arrow/benches/take_kernels.rs index fb231771681c..a10f80c5907b 100644 --- a/arrow/benches/take_kernels.rs +++ b/arrow/benches/take_kernels.rs @@ -186,6 +186,66 @@ fn add_benchmark(c: &mut Criterion) { b.iter(|| bench_take(&values, &indices)) }); + let values = create_primitive_list_array::(512, 0.0, 0.0, 20); + let indices = create_random_index(512, 0.0); + c.bench_function("take list i32 512", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_array::(1024, 0.0, 0.0, 20); + let indices = create_random_index(1024, 0.0); + c.bench_function("take list i32 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_array::(1024, 0.5, 0.0, 20); + let indices = create_random_index(1024, 0.0); + c.bench_function("take list i32 null values 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_array::(1024, 0.0, 0.0, 202); + let indices = create_random_index(1024, 0.5); + c.bench_function("take list i32 null indices 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_array::(1024, 0.5, 0.5, 20); + let indices = create_random_index(1024, 0.5); + c.bench_function("take list i32 null values null indices 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_view_array::(512, 0.0, 0.0, 20); + let indices = create_random_index(512, 0.0); + c.bench_function("take listview i32 512", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_view_array::(1024, 0.0, 0.0, 20); + let indices = create_random_index(1024, 0.0); + c.bench_function("take listview i32 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_view_array::(1024, 0.5, 0.0, 20); + let indices = create_random_index(1024, 0.0); + c.bench_function("take listview i32 null values 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_view_array::(1024, 0.0, 0.0, 20); + let indices = create_random_index(1024, 0.5); + c.bench_function("take listview i32 null indices 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + + let values = create_primitive_list_view_array::(1024, 0.5, 0.5, 20); + let indices = create_random_index(1024, 0.5); + c.bench_function("take listview i32 null values null indices 1024", |b| { + b.iter(|| bench_take(&values, &indices)) + }); + let values = create_primitive_run_array::(1024, 512); let indices = create_random_index(1024, 0.0); c.bench_function( diff --git a/arrow/src/util/bench_util.rs b/arrow/src/util/bench_util.rs index fefb9077b164..aba95ba4aaa0 100644 --- a/arrow/src/util/bench_util.rs +++ b/arrow/src/util/bench_util.rs @@ -491,6 +491,80 @@ where GenericListArray::::from_iter_primitive::(values) } +/// Create a List/LargeList Array of primitive values using a fixed seed +/// +/// See [`create_primitive_list_array_with_seed`] for details on arguments. +pub fn create_primitive_list_array( + size: usize, + null_density: f32, + list_null_density: f32, + max_list_size: usize, +) -> GenericListArray +where + O: OffsetSizeTrait, + T: ArrowPrimitiveType, + StandardUniform: Distribution, +{ + let mut rng = seedable_rng(); + + let values = (0..size).map(|_| { + if rng.random::() < null_density { + None + } else { + let list_size = rng.random_range(0..=max_list_size); + let list_values: Vec> = (0..list_size) + .map(|_| { + if rng.random::() < list_null_density { + None + } else { + Some(rng.random()) + } + }) + .collect(); + Some(list_values) + } + }); + + GenericListArray::::from_iter_primitive::(values) +} + +/// Create a ListViewArray of primitive values using a fixed seed +/// +/// See [`create_primitive_list_array_with_seed`] for details on arguments. +pub fn create_primitive_list_view_array( + size: usize, + null_density: f32, + list_null_density: f32, + max_list_size: usize, +) -> GenericListViewArray +where + T: ArrowPrimitiveType, + StandardUniform: Distribution, + O: OffsetSizeTrait, +{ + let mut rng = seedable_rng(); + + let values = (0..size).map(|_| { + if rng.random::() < null_density { + None + } else { + let list_size = rng.random_range(0..=max_list_size); + let list_values: Vec> = (0..list_size) + .map(|_| { + if rng.random::() < list_null_density { + None + } else { + Some(rng.random()) + } + }) + .collect(); + Some(list_values) + } + }); + + GenericListViewArray::::from_iter_primitive::(values) +} + /// Create primitive run array for given logical and physical array lengths pub fn create_primitive_run_array( logical_array_len: usize,