Skip to content

Commit ca28428

Browse files
authored
Improve varbin take benchmarks (#4751)
Sets a baseline for #4749 Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 613f756 commit ca28428

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

vortex-array/benches/take_strings.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#![allow(clippy::unwrap_used)]
55

66
use divan::Bencher;
7+
use rand::rngs::StdRng;
8+
use rand::{Rng, SeedableRng};
79
use vortex_array::arrays::VarBinArray;
810
use vortex_array::compute::take;
911
use vortex_array::{ArrayRef, IntoArray, ToCanonical};
@@ -17,7 +19,7 @@ fn main() {
1719
#[divan::bench]
1820
fn varbin(bencher: Bencher) {
1921
let array = fixture(65_535);
20-
let indices = indices(1024);
22+
let indices = indices(1024, 65_535);
2123

2224
bencher
2325
.with_inputs(|| (&array, &indices))
@@ -27,7 +29,27 @@ fn varbin(bencher: Bencher) {
2729
#[divan::bench]
2830
fn varbinview(bencher: Bencher) {
2931
let array = fixture(65_535).to_varbinview();
30-
let indices = indices(1024);
32+
let indices = indices(1024, 65_535);
33+
34+
bencher
35+
.with_inputs(|| (&array, &indices))
36+
.bench_refs(|(array, indices)| take(array.as_ref(), indices.as_ref()).unwrap());
37+
}
38+
39+
#[divan::bench]
40+
fn varbin_non_null(bencher: Bencher) {
41+
let array = non_null_fixutre(65_535);
42+
let indices = indices(1024, 65_535);
43+
44+
bencher
45+
.with_inputs(|| (&array, &indices))
46+
.bench_refs(|(array, indices)| take(array.as_ref(), indices.as_ref()).unwrap());
47+
}
48+
49+
#[divan::bench]
50+
fn varbinview_non_null(bencher: Bencher) {
51+
let array = non_null_fixutre(65_535).to_varbinview();
52+
let indices = indices(1024, 65_535);
3153

3254
bencher
3355
.with_inputs(|| (&array, &indices))
@@ -44,7 +66,18 @@ fn fixture(len: usize) -> VarBinArray {
4466
)
4567
}
4668

69+
fn non_null_fixutre(len: usize) -> VarBinArray {
70+
VarBinArray::from_iter(
71+
[Some("inlined"), Some("verylongstring--notinlined")]
72+
.into_iter()
73+
.cycle()
74+
.take(len),
75+
DType::Utf8(Nullability::Nullable),
76+
)
77+
}
78+
4779
// Fraction of the indices to take.
48-
fn indices(len: usize) -> ArrayRef {
49-
Buffer::from_iter((0..len).filter_map(|x| (x % 2 == 0).then_some(x as u64))).into_array()
80+
fn indices(desired: usize, range: usize) -> ArrayRef {
81+
let mut rng = StdRng::seed_from_u64(0);
82+
Buffer::from_iter((0..desired).map(|_| rng.random_range(0..range) as u64)).into_array()
5083
}

0 commit comments

Comments
 (0)