Skip to content

Commit b615895

Browse files
committed
Preserve existing FSL take benchmarks
Signed-off-by: Daniel King <dan@spiraldb.com>
1 parent e79ec4b commit b615895

1 file changed

Lines changed: 69 additions & 37 deletions

File tree

vortex-array/benches/take_fsl.rs

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,49 @@ static SESSION: LazyLock<VortexSession> = LazyLock::new(array_session);
4848
/// Number of lists in the source array.
4949
const NUM_LISTS: usize = 500;
5050

51-
/// Number of indices to take. This keeps even the widest, longest cases below one millisecond in
52-
/// CodSpeed's instruction-count simulation.
53-
const NUM_INDICES: &[usize] = &[10];
51+
/// Number of indices to take.
52+
const NUM_INDICES: &[usize] = &[100, 1_000];
5453

5554
/// Fixed size list lengths (elements per list).
5655
const LIST_SIZES: &[usize] = &[16, 64, 128, 256, 512, 1024, 2048, 4096];
5756

5857
/// F16 list lengths for isolating the per-index, piecewise, and manual range-copy strategies.
5958
const F16_STRATEGY_LIST_SIZES: &[usize] = &[1, 2, 4, 8, 16, 64, 128, 256, 512, 1024, 2048, 4096];
6059

60+
/// F16 strategy benchmarks keep a smaller take width so the forced slow strategies stay cheap.
61+
const F16_STRATEGY_NUM_INDICES: &[usize] = &[10];
62+
6163
/// Creates a FixedSizeListArray with the given list size and number of lists.
6264
fn create_fsl<T>(list_size: usize, num_lists: usize) -> FixedSizeListArray
65+
where
66+
T: NativePType + FromPrimitive,
67+
{
68+
create_fsl_with_validity::<T>(list_size, num_lists, Validity::NonNullable)
69+
}
70+
71+
fn create_fsl_with_validity<T>(
72+
list_size: usize,
73+
num_lists: usize,
74+
validity: Validity,
75+
) -> FixedSizeListArray
6376
where
6477
T: NativePType + FromPrimitive,
6578
{
6679
let total_elements = list_size * num_lists;
6780
let elements: Buffer<T> = (0..total_elements)
6881
.map(|idx| T::from_u16((idx % 251) as u16).unwrap())
6982
.collect();
70-
FixedSizeListArray::new(
71-
elements.into_array(),
72-
list_size as u32,
73-
Validity::NonNullable,
74-
num_lists,
75-
)
83+
FixedSizeListArray::new(elements.into_array(), list_size as u32, validity, num_lists)
84+
}
85+
86+
fn create_i64_fsl_with_validity(
87+
list_size: usize,
88+
num_lists: usize,
89+
validity: Validity,
90+
) -> FixedSizeListArray {
91+
let total_elements = list_size * num_lists;
92+
let elements: Buffer<i64> = (0..total_elements as i64).collect();
93+
FixedSizeListArray::new(elements.into_array(), list_size as u32, validity, num_lists)
7694
}
7795

7896
/// Creates random indices for taking from the array.
@@ -83,31 +101,47 @@ fn create_random_indices(num_indices: usize, max_index: usize) -> Buffer<u64> {
83101
.collect()
84102
}
85103

104+
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
105+
fn take_fsl_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
106+
let fsl = create_i64_fsl_with_validity(LIST_SIZE, NUM_LISTS, Validity::NonNullable);
107+
bench_take_fsl_random::<i64, LIST_SIZE>(bencher, num_indices, fsl);
108+
}
109+
86110
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
87111
fn take_fsl_f16_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
88-
take_fsl_random::<f16, LIST_SIZE>(bencher, num_indices);
112+
take_fsl_random_typed::<f16, LIST_SIZE>(bencher, num_indices);
89113
}
90114

91115
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
92116
fn take_fsl_u8_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
93-
take_fsl_random::<u8, LIST_SIZE>(bencher, num_indices);
117+
take_fsl_random_typed::<u8, LIST_SIZE>(bencher, num_indices);
94118
}
95119

96120
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
97121
fn take_fsl_u32_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
98-
take_fsl_random::<u32, LIST_SIZE>(bencher, num_indices);
122+
take_fsl_random_typed::<u32, LIST_SIZE>(bencher, num_indices);
99123
}
100124

101125
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
102126
fn take_fsl_u64_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
103-
take_fsl_random::<u64, LIST_SIZE>(bencher, num_indices);
127+
take_fsl_random_typed::<u64, LIST_SIZE>(bencher, num_indices);
104128
}
105129

106-
fn take_fsl_random<T, const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize)
130+
fn take_fsl_random_typed<T, const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize)
107131
where
108132
T: NativePType + FromPrimitive,
109133
{
110134
let fsl = create_fsl::<T>(LIST_SIZE, NUM_LISTS);
135+
bench_take_fsl_random::<T, LIST_SIZE>(bencher, num_indices, fsl);
136+
}
137+
138+
fn bench_take_fsl_random<T, const LIST_SIZE: usize>(
139+
bencher: Bencher,
140+
num_indices: usize,
141+
fsl: FixedSizeListArray,
142+
) where
143+
T: NativePType,
144+
{
111145
let indices = create_random_indices(num_indices, NUM_LISTS);
112146
let indices_array = indices.into_array();
113147

@@ -124,7 +158,7 @@ where
124158
});
125159
}
126160

127-
#[divan::bench(args = NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
161+
#[divan::bench(args = F16_STRATEGY_NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
128162
fn take_fsl_f16_force_per_index<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
129163
let fsl = create_fsl::<f16>(LIST_SIZE, NUM_LISTS);
130164
let indices = create_random_indices(num_indices, NUM_LISTS);
@@ -142,7 +176,7 @@ fn take_fsl_f16_force_per_index<const LIST_SIZE: usize>(bencher: Bencher, num_in
142176
});
143177
}
144178

145-
#[divan::bench(args = NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
179+
#[divan::bench(args = F16_STRATEGY_NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
146180
fn take_fsl_f16_force_piecewise_sequence<const LIST_SIZE: usize>(
147181
bencher: Bencher,
148182
num_indices: usize,
@@ -161,7 +195,7 @@ fn take_fsl_f16_force_piecewise_sequence<const LIST_SIZE: usize>(
161195
});
162196
}
163197

164-
#[divan::bench(args = NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
198+
#[divan::bench(args = F16_STRATEGY_NUM_INDICES, consts = F16_STRATEGY_LIST_SIZES)]
165199
fn take_fsl_f16_force_manual_range_copy<const LIST_SIZE: usize>(
166200
bencher: Bencher,
167201
num_indices: usize,
@@ -281,30 +315,28 @@ fn take_fsl_f16_manual_range_copy_strategy<const LIST_SIZE: usize>(
281315
}
282316

283317
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
284-
fn take_fsl_f16_nullable_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
285-
let total_elements = LIST_SIZE * NUM_LISTS;
286-
let elements: Buffer<f16> = (0..total_elements)
287-
.map(|idx| f16::from_u16((idx % 251) as u16).unwrap())
288-
.collect();
289-
318+
fn take_fsl_nullable_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
290319
// Create validity with ~10% nulls
291320
let mut rng = StdRng::seed_from_u64(123);
292321
let validity = Validity::from_iter((0..NUM_LISTS).map(|_| rng.random_ratio(9, 10)));
293322

294-
let fsl = FixedSizeListArray::new(elements.into_array(), LIST_SIZE as u32, validity, NUM_LISTS);
323+
let fsl = create_i64_fsl_with_validity(LIST_SIZE, NUM_LISTS, validity);
324+
bench_take_fsl_random::<i64, LIST_SIZE>(bencher, num_indices, fsl);
325+
}
295326

296-
let indices = create_random_indices(num_indices, NUM_LISTS);
297-
let indices_array = indices.into_array();
327+
#[divan::bench(args = NUM_INDICES, consts = LIST_SIZES)]
328+
fn take_fsl_f16_nullable_random<const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize) {
329+
take_fsl_nullable_random_typed::<f16, LIST_SIZE>(bencher, num_indices);
330+
}
298331

299-
bencher
300-
.counter(BytesCount::of_many::<f16>(num_indices * LIST_SIZE))
301-
.with_inputs(|| (&fsl, &indices_array, SESSION.create_execution_ctx()))
302-
.bench_refs(|(array, indices, execution_ctx)| {
303-
array
304-
.clone()
305-
.take(indices.clone())
306-
.unwrap()
307-
.execute::<RecursiveCanonical>(execution_ctx)
308-
.unwrap()
309-
});
332+
fn take_fsl_nullable_random_typed<T, const LIST_SIZE: usize>(bencher: Bencher, num_indices: usize)
333+
where
334+
T: NativePType + FromPrimitive,
335+
{
336+
// Create validity with ~10% nulls
337+
let mut rng = StdRng::seed_from_u64(123);
338+
let validity = Validity::from_iter((0..NUM_LISTS).map(|_| rng.random_ratio(9, 10)));
339+
340+
let fsl = create_fsl_with_validity::<T>(LIST_SIZE, NUM_LISTS, validity);
341+
bench_take_fsl_random::<T, LIST_SIZE>(bencher, num_indices, fsl);
310342
}

0 commit comments

Comments
 (0)