Skip to content

Commit 7ed76bc

Browse files
committed
w
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 74216c1 commit 7ed76bc

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

vortex-array/benches/cast_primitive.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
#![expect(clippy::unwrap_used)]
5+
46
use std::sync::LazyLock;
57

68
use divan::Bencher;
@@ -28,12 +30,12 @@ const SIZES: &[usize] = &[65_536];
2830
static SESSION: LazyLock<VortexSession> =
2931
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());
3032

31-
#[divan::bench]
32-
fn cast_u16_to_u32(bencher: Bencher) {
33+
#[divan::bench(args = SIZES)]
34+
fn cast_u16_to_u32(bencher: Bencher, n: usize) {
3335
let mut rng = StdRng::seed_from_u64(42);
3436
let arr = PrimitiveArray::from_option_iter((0..n).map(|i| {
3537
#[expect(clippy::cast_possible_truncation)]
36-
rng.random_bool(0.5).then(|| i as u16)
38+
rng.random_bool(0.5).then_some(i as u16)
3739
}))
3840
.into_array();
3941
// Pre-compute min/max so values_fit_in is a cache hit during the benchmark.
@@ -43,7 +45,6 @@ fn cast_u16_to_u32(bencher: Bencher) {
4345
bencher
4446
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
4547
.bench_refs(|(a, ctx)| {
46-
#[expect(clippy::unwrap_used)]
4748
a.cast(DType::Primitive(PType::U32, Nullability::Nullable))
4849
.unwrap()
4950
.execute::<Canonical>(ctx)
@@ -60,12 +61,13 @@ fn cast_u32_to_u8(bencher: Bencher, n: usize) {
6061
.then(|| rng.random_range(0..u8::MAX) as u32)
6162
}))
6263
.into_array();
63-
bencher.with_inputs(|| arr.clone()).bench_refs(|a| {
64-
#[expect(clippy::unwrap_used)]
65-
a.cast(DType::Primitive(PType::U8, Nullability::Nullable))
66-
.unwrap()
67-
.execute::<Canonical>(&mut LEGACY_SESSION.create_execution_ctx())
68-
});
64+
bencher
65+
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
66+
.bench_refs(|(a, ctx)| {
67+
a.cast(DType::Primitive(PType::U8, Nullability::Nullable))
68+
.unwrap()
69+
.execute::<Canonical>(ctx)
70+
});
6971
}
7072

7173
/// Sign-change cast i32 → u32. Values are non-negative so the kernel succeeds
@@ -77,10 +79,11 @@ fn cast_i32_to_u32(bencher: Bencher, n: usize) {
7779
(0..n).map(|_| rng.random_bool(0.7).then(|| rng.random_range(0..i32::MAX))),
7880
)
7981
.into_array();
80-
bencher.with_inputs(|| arr.clone()).bench_refs(|a| {
81-
#[expect(clippy::unwrap_used)]
82-
a.cast(DType::Primitive(PType::U32, Nullability::Nullable))
83-
.unwrap()
84-
.execute::<Canonical>(&mut LEGACY_SESSION.create_execution_ctx())
85-
});
82+
bencher
83+
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
84+
.bench_refs(|(a, ctx)| {
85+
a.cast(DType::Primitive(PType::U32, Nullability::Nullable))
86+
.unwrap()
87+
.execute::<Canonical>(ctx)
88+
});
8689
}

0 commit comments

Comments
 (0)