Skip to content

Commit 8261ebf

Browse files
authored
varbinview zip bench (#5518)
Signed-off-by: Onur Satici <[email protected]>
1 parent c241f59 commit 8261ebf

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

vortex-array/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ harness = false
163163
[[bench]]
164164
name = "dict_unreferenced_mask"
165165
harness = false
166+
167+
[[bench]]
168+
name = "varbinview_zip"
169+
harness = false
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
#![allow(clippy::unwrap_used)]
5+
6+
use divan::Bencher;
7+
use vortex_array::IntoArray;
8+
use vortex_array::arrays::VarBinViewArray;
9+
use vortex_array::compute::zip;
10+
use vortex_dtype::DType;
11+
use vortex_dtype::Nullability;
12+
use vortex_mask::Mask;
13+
14+
fn main() {
15+
divan::main();
16+
}
17+
18+
/// Benchmarks zip on VarBinView arrays with a highly fragmented mask (worst case for per-slice lookup paths).
19+
#[divan::bench]
20+
fn varbinview_zip_fragmented_mask(bencher: Bencher) {
21+
let len = 65_536;
22+
let if_true = fixture(len).into_array();
23+
let if_false = other_fixture(len).into_array();
24+
let mask = alternating_mask(len);
25+
26+
bencher
27+
.with_inputs(|| (&if_true, &if_false, &mask))
28+
.bench_refs(|(t, f, m)| {
29+
zip(t.as_ref(), f.as_ref(), m).unwrap();
30+
});
31+
}
32+
33+
/// Benchmarks zip on VarBinView arrays with blocky mask segments to contrast with the fragmented case.
34+
#[divan::bench]
35+
fn varbinview_zip_block_mask(bencher: Bencher) {
36+
let len = 65_536;
37+
let if_true = fixture(len).into_array();
38+
let if_false = other_fixture(len).into_array();
39+
let mask = block_mask(len, 128);
40+
41+
bencher
42+
.with_inputs(|| (&if_true, &if_false, &mask))
43+
.bench_refs(|(t, f, m)| {
44+
zip(t.as_ref(), f.as_ref(), m).unwrap();
45+
});
46+
}
47+
48+
fn fixture(len: usize) -> VarBinViewArray {
49+
VarBinViewArray::from_iter(
50+
[
51+
Some("short"),
52+
None,
53+
Some("this is a much longer string to force outlining"),
54+
]
55+
.into_iter()
56+
.cycle()
57+
.take(len),
58+
DType::Utf8(Nullability::Nullable),
59+
)
60+
}
61+
62+
fn other_fixture(len: usize) -> VarBinViewArray {
63+
VarBinViewArray::from_iter(
64+
[
65+
Some("different"),
66+
Some("another longer string that will be outlined as well"),
67+
None,
68+
]
69+
.into_iter()
70+
.cycle()
71+
.take(len),
72+
DType::Utf8(Nullability::Nullable),
73+
)
74+
}
75+
76+
fn alternating_mask(len: usize) -> Mask {
77+
Mask::from_iter((0..len).map(|i| i % 2 == 0))
78+
}
79+
80+
fn block_mask(len: usize, block: usize) -> Mask {
81+
Mask::from_iter((0..len).map(|i| (i / block) % 2 == 0))
82+
}

0 commit comments

Comments
 (0)