Skip to content

Commit 32a80b1

Browse files
committed
Benchmark decimal byte-part assembly and splitting
Cover i64, i128, and i256 assembly through DecimalArray execution. Add split benchmarks for all-valid, mixed-null, and clustered-null inputs, with shared fixtures and setup outside the timed region. Signed-off-by: "Matt Katz" <mhkatz97@gmail.com>
1 parent fb03094 commit 32a80b1

5 files changed

Lines changed: 153 additions & 107 deletions

File tree

‎encodings/decimal-byte-parts/Cargo.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ rstest = { workspace = true }
3333
vortex-array = { path = "../../vortex-array", features = ["_test-harness"] }
3434

3535
[[bench]]
36-
name = "decimal_assemble"
36+
name = "dbp_assemble"
37+
harness = false
38+
39+
[[bench]]
40+
name = "dbp_split"
3741
harness = false
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Shared decimal inputs for splitting and assembly benchmarks.
5+
6+
use rand::RngExt;
7+
use rand::SeedableRng;
8+
use rand::rngs::StdRng;
9+
use vortex_array::arrays::DecimalArray;
10+
use vortex_array::dtype::DecimalDType;
11+
use vortex_array::dtype::DecimalType;
12+
use vortex_array::dtype::i256;
13+
use vortex_array::validity::Validity;
14+
use vortex_buffer::Buffer;
15+
use vortex_error::vortex_panic;
16+
17+
pub(super) const LEN: usize = 65_536;
18+
19+
pub(super) const DECIMAL_TYPES: &[DecimalType] =
20+
&[DecimalType::I64, DecimalType::I128, DecimalType::I256];
21+
22+
pub(super) fn decimal_array(values_type: DecimalType, validity: Validity) -> DecimalArray {
23+
let mut rng = StdRng::seed_from_u64(42);
24+
25+
macro_rules! decimal {
26+
($T:ty, $precision:literal) => {{
27+
let max = <$T>::pow(10, $precision) - 1;
28+
let values: Buffer<$T> = (0..LEN).map(|_| rng.random_range(-max..=max)).collect();
29+
DecimalArray::new(values, DecimalDType::new($precision, 2), validity)
30+
}};
31+
}
32+
33+
match values_type {
34+
DecimalType::I64 => decimal!(i64, 18),
35+
DecimalType::I128 => decimal!(i128, 38),
36+
DecimalType::I256 => {
37+
// Keep the magnitude below 10^76 while exercising all four signed/unsigned words.
38+
let values: Buffer<i256> = (0..LEN)
39+
.map(|_| i256::from_parts(rng.random(), rng.random::<i128>() >> 4))
40+
.collect();
41+
DecimalArray::new(values, DecimalDType::new(76, 2), validity)
42+
}
43+
_ => vortex_panic!("unsupported benchmark storage type: {values_type}"),
44+
}
45+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Executing decimal byte parts into canonical decimal arrays.
5+
6+
mod common;
7+
8+
use divan::Bencher;
9+
use divan::black_box;
10+
use vortex_array::IntoArray;
11+
use vortex_array::VortexSessionExecute;
12+
use vortex_array::array_session;
13+
use vortex_array::arrays::DecimalArray;
14+
use vortex_array::dtype::DecimalType;
15+
use vortex_array::validity::Validity;
16+
use vortex_decimal_byte_parts::DecimalByteParts;
17+
use vortex_decimal_byte_parts::split_decimal;
18+
use vortex_error::VortexExpect;
19+
20+
use crate::common::DECIMAL_TYPES;
21+
use crate::common::decimal_array;
22+
23+
fn main() {
24+
divan::main();
25+
}
26+
27+
#[divan::bench(args = DECIMAL_TYPES)]
28+
fn assemble(bencher: Bencher, values_type: DecimalType) {
29+
let decimal = decimal_array(values_type, Validity::NonNullable);
30+
let parts = split_decimal(&decimal, &mut array_session().create_execution_ctx())
31+
.vortex_expect("split benchmark input");
32+
let dbp = DecimalByteParts::try_new_with_lower_parts(
33+
parts.msp,
34+
parts.lower_parts,
35+
decimal.decimal_dtype(),
36+
)
37+
.vortex_expect("construct decimal byte parts")
38+
.into_array();
39+
40+
let session = array_session();
41+
bencher
42+
.with_inputs(|| session.create_execution_ctx())
43+
.bench_refs(|ctx| {
44+
black_box(dbp.clone())
45+
.execute::<DecimalArray>(ctx)
46+
.vortex_expect("assemble decimal byte parts")
47+
});
48+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Splitting decimal arrays across storage widths and validity paths.
5+
6+
mod common;
7+
8+
use divan::Bencher;
9+
use divan::black_box;
10+
use rand::RngExt;
11+
use rand::SeedableRng;
12+
use rand::rngs::StdRng;
13+
use vortex_array::VortexSessionExecute;
14+
use vortex_array::array_session;
15+
use vortex_array::dtype::DecimalType;
16+
use vortex_array::validity::Validity;
17+
use vortex_decimal_byte_parts::split_decimal;
18+
use vortex_error::VortexExpect;
19+
20+
use crate::common::DECIMAL_TYPES;
21+
use crate::common::LEN;
22+
use crate::common::decimal_array;
23+
24+
fn main() {
25+
divan::main();
26+
}
27+
28+
#[divan::bench(args = DECIMAL_TYPES)]
29+
fn all_valid(bencher: Bencher, values_type: DecimalType) {
30+
bench_split(bencher, values_type, Validity::AllValid);
31+
}
32+
33+
#[divan::bench(args = DECIMAL_TYPES)]
34+
fn mixed_nulls(bencher: Bencher, values_type: DecimalType) {
35+
let mut rng = StdRng::seed_from_u64(42);
36+
let validity = Validity::from_iter((0..LEN).map(|_| rng.random_bool(0.5)));
37+
bench_split(bencher, values_type, validity);
38+
}
39+
40+
#[divan::bench(args = DECIMAL_TYPES)]
41+
fn clustered_nulls(bencher: Bencher, values_type: DecimalType) {
42+
const CLUSTER_LEN: usize = 1_024;
43+
let validity = Validity::from_iter((0..LEN).map(|i| (i / CLUSTER_LEN).is_multiple_of(2)));
44+
bench_split(bencher, values_type, validity);
45+
}
46+
47+
fn bench_split(bencher: Bencher, values_type: DecimalType, validity: Validity) {
48+
let decimal = decimal_array(values_type, validity);
49+
let session = array_session();
50+
bencher
51+
.with_inputs(|| session.create_execution_ctx())
52+
.bench_refs(|ctx| {
53+
split_decimal(black_box(&decimal), ctx).vortex_expect("split decimal array")
54+
});
55+
}

‎encodings/decimal-byte-parts/benches/decimal_assemble.rs‎

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)