Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions vortex-array/benches/cast_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use vortex_array::array_session;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::DType;
use vortex_array::dtype::DecimalDType;
use vortex_array::dtype::Nullability;
use vortex_array::dtype::PType;
use vortex_array::expr::stats::Stat;
Expand Down Expand Up @@ -87,3 +88,55 @@ fn cast_i32_to_u32(bencher: Bencher, n: usize) {
.execute::<Canonical>(ctx)
});
}

/// Integer-to-decimal cast at the largest precision that uses an i128 backing buffer. This
/// exercises the common rescaling path without paying for i256 arithmetic per input value.
#[divan::bench(args = SIZES)]
fn cast_i64_to_decimal38_scale2(bencher: Bencher, n: usize) {
let arr =
PrimitiveArray::from_iter((0..n).map(|value| i64::try_from(value).unwrap())).into_array();
bencher
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
.bench_refs(|(a, ctx)| {
a.cast(DType::Decimal(
DecimalDType::new(38, 2),
Nullability::NonNullable,
))
.unwrap()
.execute::<Canonical>(ctx)
});
}

/// Common integer-to-decimal cast that rescales directly in its i32 output buffer.
#[divan::bench(args = SIZES)]
fn cast_i32_to_decimal9_scale2(bencher: Bencher, n: usize) {
let arr =
PrimitiveArray::from_iter((0..n).map(|value| i32::try_from(value).unwrap())).into_array();
bencher
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
.bench_refs(|(a, ctx)| {
a.cast(DType::Decimal(
DecimalDType::new(9, 2),
Nullability::NonNullable,
))
.unwrap()
.execute::<Canonical>(ctx)
});
}

/// Same-width scale-zero cast that validates then reuses the source values buffer.
#[divan::bench(args = SIZES)]
fn cast_i32_to_decimal9_scale0(bencher: Bencher, n: usize) {
let arr =
PrimitiveArray::from_iter((0..n).map(|value| i32::try_from(value).unwrap())).into_array();
bencher
.with_inputs(|| (arr.clone(), SESSION.create_execution_ctx()))
.bench_refs(|(a, ctx)| {
a.cast(DType::Decimal(
DecimalDType::new(9, 0),
Nullability::NonNullable,
))
.unwrap()
.execute::<Canonical>(ctx)
});
}
Loading
Loading