Skip to content

Commit 2d135fa

Browse files
committed
chore: minimize with_inputs work for benchmark
Signed-off-by: Alexander Droste <[email protected]>
1 parent 3572526 commit 2d135fa

File tree

11 files changed

+160
-149
lines changed

11 files changed

+160
-149
lines changed

encodings/fastlanes/benches/bitpacking_decompress_selection.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rand::rngs::StdRng;
1313
use rand::{Rng as _, SeedableRng as _};
1414
use vortex_array::compute::{filter, warm_up_vtables};
1515
use vortex_array::{Array, IntoArray as _, ToCanonical};
16-
use vortex_buffer::BufferMut;
16+
use vortex_buffer::{BitBuffer, BufferMut};
1717
use vortex_dtype::IntegerPType;
1818
use vortex_fastlanes::bitpack_compress::bitpack_to_best_bit_width;
1919
use vortex_mask::Mask;
@@ -35,12 +35,11 @@ fn decompress_bitpacking_early_filter<T: IntegerPType>(bencher: Bencher, fractio
3535
let array = bitpack_to_best_bit_width(&values).unwrap();
3636
let mask = (0..100_000)
3737
.map(|_| rng.random_bool(fraction_kept))
38-
.collect();
39-
40-
let mask = Mask::from_buffer(mask);
38+
.collect::<BitBuffer>();
4139

4240
bencher
43-
.with_inputs(|| (array.clone(), mask.clone()))
41+
// Be sure to reconstruct the mask to avoid cached set_indices
42+
.with_inputs(|| (&array, Mask::from_buffer(mask.clone())))
4443
.bench_refs(|(array, mask)| filter(array.as_ref(), mask).unwrap().to_canonical());
4544
}
4645

@@ -58,11 +57,10 @@ fn decompress_bitpacking_late_filter<T: IntegerPType>(bencher: Bencher, fraction
5857

5958
let mask = (0..100_000)
6059
.map(|_| rng.random_bool(fraction_kept))
61-
.collect();
62-
63-
let mask = Mask::from_buffer(mask);
60+
.collect::<BitBuffer>();
6461

6562
bencher
66-
.with_inputs(|| (array.clone(), mask.clone()))
63+
// Be sure to reconstruct the mask to avoid cached set_indices
64+
.with_inputs(|| (&array, Mask::from_buffer(mask.clone())))
6765
.bench_refs(|(array, mask)| filter(array.to_canonical().as_ref(), mask).unwrap());
6866
}

encodings/fastlanes/benches/bitpacking_take.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn take_10_stratified(bencher: Bencher) {
2828
let indices = PrimitiveArray::from_iter((0..10).map(|i| i * 10_000));
2929

3030
bencher
31-
.with_inputs(|| (packed.clone(), indices.clone()))
31+
.with_inputs(|| (&packed, &indices))
3232
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
3333
}
3434

@@ -40,7 +40,7 @@ fn take_10_contiguous(bencher: Bencher) {
4040
let indices = buffer![0..10].into_array();
4141

4242
bencher
43-
.with_inputs(|| (packed.clone(), indices.clone()))
43+
.with_inputs(|| (&packed, &indices))
4444
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
4545
}
4646

@@ -55,7 +55,7 @@ fn take_10k_random(bencher: Bencher) {
5555
let indices = PrimitiveArray::from_iter(rng.sample_iter(range).take(10_000).map(|i| i as u32));
5656

5757
bencher
58-
.with_inputs(|| (packed.clone(), indices.clone()))
58+
.with_inputs(|| (&packed, &indices))
5959
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
6060
}
6161

@@ -67,7 +67,7 @@ fn take_10k_contiguous(bencher: Bencher) {
6767
let indices = PrimitiveArray::from_iter(0..10_000);
6868

6969
bencher
70-
.with_inputs(|| (packed.clone(), indices.clone()))
70+
.with_inputs(|| (&packed, &indices))
7171
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
7272
}
7373

@@ -79,7 +79,7 @@ fn take_200k_dispersed(bencher: Bencher) {
7979
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| (i * 42) % values.len() as u64));
8080

8181
bencher
82-
.with_inputs(|| (packed.clone(), indices.clone()))
82+
.with_inputs(|| (&packed, &indices))
8383
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
8484
}
8585

@@ -91,7 +91,7 @@ fn take_200k_first_chunk_only(bencher: Bencher) {
9191
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| ((i * 42) % 1024) as u64));
9292

9393
bencher
94-
.with_inputs(|| (packed.clone(), indices.clone()))
94+
.with_inputs(|| (&packed, &indices))
9595
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
9696
}
9797

@@ -130,7 +130,7 @@ fn patched_take_10_stratified(bencher: Bencher) {
130130
let indices = PrimitiveArray::from_iter((0..10).map(|i| i * 10_000));
131131

132132
bencher
133-
.with_inputs(|| (packed.clone(), indices.clone()))
133+
.with_inputs(|| (&packed, &indices))
134134
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
135135
}
136136

@@ -149,7 +149,7 @@ fn patched_take_10_contiguous(bencher: Bencher) {
149149
let indices = buffer![0..10].into_array();
150150

151151
bencher
152-
.with_inputs(|| (packed.clone(), indices.clone()))
152+
.with_inputs(|| (&packed, &indices))
153153
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
154154
}
155155

@@ -164,7 +164,7 @@ fn patched_take_10k_random(bencher: Bencher) {
164164
let indices = PrimitiveArray::from_iter(rng.sample_iter(range).take(10_000).map(|i| i as u32));
165165

166166
bencher
167-
.with_inputs(|| (packed.clone(), indices.clone()))
167+
.with_inputs(|| (&packed, &indices))
168168
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
169169
}
170170

@@ -176,7 +176,7 @@ fn patched_take_10k_contiguous_not_patches(bencher: Bencher) {
176176
let indices = PrimitiveArray::from_iter((0u32..NUM_EXCEPTIONS).cycle().take(10000));
177177

178178
bencher
179-
.with_inputs(|| (packed.clone(), indices.clone()))
179+
.with_inputs(|| (&packed, &indices))
180180
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
181181
}
182182

@@ -196,7 +196,7 @@ fn patched_take_10k_contiguous_patches(bencher: Bencher) {
196196
PrimitiveArray::from_iter((BIG_BASE2..BIG_BASE2 + NUM_EXCEPTIONS).cycle().take(10000));
197197

198198
bencher
199-
.with_inputs(|| (packed.clone(), indices.clone()))
199+
.with_inputs(|| (&packed, &indices))
200200
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
201201
}
202202

@@ -208,7 +208,7 @@ fn patched_take_200k_dispersed(bencher: Bencher) {
208208
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| (i * 42) % values.len() as u64));
209209

210210
bencher
211-
.with_inputs(|| (packed.clone(), indices.clone()))
211+
.with_inputs(|| (&packed, &indices))
212212
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
213213
}
214214

@@ -220,7 +220,7 @@ fn patched_take_200k_first_chunk_only(bencher: Bencher) {
220220
let indices = PrimitiveArray::from_iter((0..200_000).map(|i| ((i * 42) % 1024) as u64));
221221

222222
bencher
223-
.with_inputs(|| (packed.clone(), indices.clone()))
223+
.with_inputs(|| (&packed, &indices))
224224
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
225225
}
226226

@@ -239,6 +239,6 @@ fn patched_take_10k_adversarial(bencher: Bencher) {
239239
);
240240

241241
bencher
242-
.with_inputs(|| (packed.clone(), indices.clone()))
242+
.with_inputs(|| (&packed, &indices))
243243
.bench_refs(|(packed, indices)| take(packed.as_ref(), indices.as_ref()).unwrap())
244244
}

encodings/fastlanes/benches/canonicalize_bench.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn into_canonical_non_nullable(
4545
let chunked = ChunkedArray::from_iter(chunks).into_array();
4646

4747
bencher
48-
.with_inputs(|| chunked.clone())
48+
.with_inputs(|| &chunked)
4949
.bench_refs(|chunked| chunked.to_canonical());
5050
}
5151

@@ -63,16 +63,14 @@ fn canonical_into_non_nullable(
6363
.collect::<Vec<_>>();
6464
let chunked = ChunkedArray::from_iter(chunks).into_array();
6565

66-
bencher
67-
.with_inputs(|| chunked.clone())
68-
.bench_refs(|chunked| {
69-
let mut primitive_builder = PrimitiveBuilder::<i32>::with_capacity(
70-
chunked.dtype().nullability(),
71-
chunk_len * chunk_count,
72-
);
73-
chunked.append_to_builder(&mut primitive_builder);
74-
primitive_builder.finish()
75-
});
66+
bencher.with_inputs(|| &chunked).bench_refs(|chunked| {
67+
let mut primitive_builder = PrimitiveBuilder::<i32>::with_capacity(
68+
chunked.dtype().nullability(),
69+
chunk_len * chunk_count,
70+
);
71+
chunked.append_to_builder(&mut primitive_builder);
72+
primitive_builder.finish()
73+
});
7674
}
7775

7876
const NULLABLE_BENCH_ARGS: &[(usize, usize, f64)] = &[
@@ -101,7 +99,7 @@ fn into_canonical_nullable(
10199
let chunked = ChunkedArray::from_iter(chunks).into_array();
102100

103101
bencher
104-
.with_inputs(|| chunked.clone())
102+
.with_inputs(|| &chunked)
105103
.bench_refs(|chunked| chunked.to_canonical());
106104
}
107105

@@ -120,14 +118,12 @@ fn canonical_into_nullable(
120118
.collect::<Vec<_>>();
121119
let chunked = ChunkedArray::from_iter(chunks).into_array();
122120

123-
bencher
124-
.with_inputs(|| chunked.clone())
125-
.bench_refs(|chunked| {
126-
let mut primitive_builder = PrimitiveBuilder::<i32>::with_capacity(
127-
chunked.dtype().nullability(),
128-
chunk_len * chunk_count,
129-
);
130-
chunked.append_to_builder(&mut primitive_builder);
131-
primitive_builder.finish()
132-
});
121+
bencher.with_inputs(|| &chunked).bench_refs(|chunked| {
122+
let mut primitive_builder = PrimitiveBuilder::<i32>::with_capacity(
123+
chunked.dtype().nullability(),
124+
chunk_len * chunk_count,
125+
);
126+
chunked.append_to_builder(&mut primitive_builder);
127+
primitive_builder.finish()
128+
});
133129
}

encodings/fastlanes/benches/compute_between.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mod alp {
240240
let mut rng = StdRng::seed_from_u64(0);
241241
let arr = generate_alp_bit_pack_primitive_array::<T>(&mut rng, len);
242242

243-
bencher.with_inputs(|| arr.clone()).bench_refs(|arr| {
243+
bencher.with_inputs(|| &arr).bench_refs(|arr| {
244244
boolean(
245245
&compare(
246246
arr.as_ref(),
@@ -273,7 +273,7 @@ mod alp {
273273
let mut rng = StdRng::seed_from_u64(0);
274274
let arr = generate_alp_bit_pack_primitive_array::<T>(&mut rng, len);
275275

276-
bencher.with_inputs(|| arr.clone()).bench_refs(|arr| {
276+
bencher.with_inputs(|| &arr).bench_refs(|arr| {
277277
between(
278278
arr.as_ref(),
279279
ConstantArray::new(min, arr.len()).as_ref(),

encodings/fastlanes/benches/pipeline_bitpacking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub fn decompress_bitpacking_late_filter<T: NativePType>(bencher: Bencher, fract
6262
.collect::<BitBuffer>();
6363

6464
bencher
65+
// Be sure to reconstruct the mask to avoid cached set_indices
6566
.with_inputs(|| Mask::from_buffer(mask.clone()))
6667
.bench_refs(|mask| filter(array.to_canonical().as_ref(), mask).unwrap());
6768
}
@@ -81,6 +82,7 @@ pub fn decompress_bitpacking_pipeline_filter<T: NativePType>(bencher: Bencher, f
8182
.collect::<BitBuffer>();
8283

8384
bencher
85+
// Be sure to reconstruct the mask to avoid cached set_indices
8486
.with_inputs(|| Mask::from(mask.clone()))
8587
.bench_refs(|mask| array.execute_with_selection(mask).unwrap());
8688
}

encodings/fastlanes/benches/pipeline_rle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ fn decompress<T: IntegerPType>(bencher: Bencher, (length, run_step): (usize, usi
7070
let rle_array = RLEArray::encode(&values).unwrap();
7171

7272
bencher
73-
.with_inputs(|| rle_array.clone())
73+
.with_inputs(|| &rle_array)
7474
.bench_refs(|rle_array| rle_array.to_canonical());
7575
}

encodings/fastlanes/benches/pipeline_v2_bitpacking_basic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ fn bitpack_canonical_unpack(bencher: Bencher, (num_elements, validity_pct): (usi
6464

6565
// Encode with 10-bit width (supports values up to 1023).
6666
let bitpacked = BitPackedArray::encode(&primitive, 10).unwrap();
67+
let array = bitpacked.to_array();
6768

6869
bencher
69-
.with_inputs(|| bitpacked.to_array())
70+
.with_inputs(|| &array)
7071
.bench_refs(|array| array.to_canonical());
7172
}

vortex-btrblocks/benches/compress.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ mod benchmarks {
3636

3737
#[divan::bench]
3838
fn btrblocks(bencher: Bencher) {
39+
let array = make_clickbench_window_name().to_primitive();
3940
bencher
40-
.with_inputs(|| make_clickbench_window_name().to_primitive())
41+
.with_inputs(|| &array)
4142
.input_counter(|array| ItemsCount::new(array.len()))
4243
.input_counter(|array| BytesCount::of_many::<i32>(array.len()))
43-
.bench_values(|array| IntCompressor::compress(&array, false, 3, &[]).unwrap());
44+
.bench_refs(|array| IntCompressor::compress(array, false, 3, &[]).unwrap());
4445
}
4546
}
4647

vortex-btrblocks/benches/dict_encode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ fn make_array() -> PrimitiveArray {
2727

2828
#[divan::bench]
2929
fn encode_generic(bencher: Bencher) {
30+
let array = make_array().into_array();
3031
bencher
31-
.with_inputs(|| make_array().into_array())
32-
.bench_values(|array| dict_encode(&array).unwrap());
32+
.with_inputs(|| &array)
33+
.bench_refs(|array| dict_encode(array.as_ref()).unwrap());
3334
}
3435

3536
#[divan::bench]
3637
fn encode_specialized(bencher: Bencher) {
38+
let stats = IntegerStats::generate(&make_array());
3739
bencher
38-
.with_inputs(|| IntegerStats::generate(&make_array()))
39-
.bench_values(|stats| integer_dictionary_encode(&stats));
40+
.with_inputs(|| &stats)
41+
.bench_refs(|stats| integer_dictionary_encode(stats));
4042
}
4143

4244
fn main() {

0 commit comments

Comments
 (0)