Skip to content

Commit 71a23d9

Browse files
committed
chore[vortex-array]: add integer casting benchmark
The motivation is to compare an upcoming perf improvement. Signed-off-by: Alfonso Subiotto Marques <alfonso.subiotto@polarsignals.com>
1 parent 4aa1c15 commit 71a23d9

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

vortex-array/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ serde_json = { workspace = true }
9696
serde_test = { workspace = true }
9797
vortex-array = { path = ".", features = ["_test-harness", "table-display"] }
9898

99+
[[bench]]
100+
name = "cast_primitive"
101+
harness = false
102+
99103
[[bench]]
100104
name = "search_sorted"
101105
harness = false
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use divan::Bencher;
5+
use rand::prelude::*;
6+
use vortex_array::IntoArray;
7+
use vortex_array::arrays::PrimitiveArray;
8+
use vortex_array::builtins::ArrayBuiltins;
9+
use vortex_array::dtype::DType;
10+
use vortex_array::dtype::Nullability;
11+
use vortex_array::dtype::PType;
12+
13+
fn main() {
14+
divan::main();
15+
}
16+
17+
const N: usize = 100_000;
18+
19+
#[divan::bench]
20+
fn cast_u16_to_u32(bencher: Bencher) {
21+
let mut rng = StdRng::seed_from_u64(42);
22+
#[expect(clippy::cast_possible_truncation)]
23+
let arr = PrimitiveArray::from_option_iter((0..N).map(|i| {
24+
if rng.random_bool(0.5) {
25+
None
26+
} else {
27+
Some(i as u16)
28+
}
29+
}))
30+
.into_array();
31+
bencher.with_inputs(|| arr.clone()).bench_refs(|a| {
32+
#[expect(clippy::unwrap_used)]
33+
a.cast(DType::Primitive(PType::U32, Nullability::Nullable))
34+
.unwrap()
35+
.to_canonical()
36+
});
37+
}

0 commit comments

Comments
 (0)