Skip to content

Commit ea43ce9

Browse files
committed
Add a decimal compress benchmark
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 5c97088 commit ea43ce9

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

‎vortex-btrblocks/benches/compress.rs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,29 @@ mod benchmarks {
1313
use divan::counter::BytesCount;
1414
use divan::counter::ItemsCount;
1515
use rand::Rng;
16+
use rand::RngExt;
1617
use rand::SeedableRng;
1718
use rand::prelude::StdRng;
1819
use vortex_array::ArrayRef;
1920
use vortex_array::IntoArray;
2021
use vortex_array::VortexSessionExecute;
2122
use vortex_array::aggregate_fn::session::AggregateFnSession;
23+
use vortex_array::arrays::DecimalArray;
2224
use vortex_array::arrays::PrimitiveArray;
25+
use vortex_array::dtype::DecimalDType;
2326
use vortex_array::memory::MemorySession;
2427
use vortex_array::optimizer::kernels::KernelSession;
2528
use vortex_array::session::ArraySession;
29+
use vortex_array::validity::Validity;
2630
use vortex_btrblocks::BtrBlocksCompressorBuilder;
2731
use vortex_btrblocks::CompressionSession;
32+
use vortex_buffer::Buffer;
2833
use vortex_buffer::buffer_mut;
34+
use vortex_edition::EDITION_DECLARATIONS;
35+
use vortex_edition::EDITION_FAMILIES;
36+
use vortex_edition::EditionSession;
37+
use vortex_edition::EditionSessionExt;
38+
use vortex_edition::declarations::core::CORE_2026_08_3;
2939
use vortex_session::VortexSession;
3040
use vortex_utils::aliases::hash_set::HashSet;
3141

@@ -38,6 +48,30 @@ mod benchmarks {
3848
.with::<CompressionSession>()
3949
});
4050

51+
/// A session that allows only what a default writer may produce, set up as the golden tests
52+
/// set it up: the encodings the compressor emits, limited by the default `core` edition.
53+
static WRITE_SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
54+
let session = VortexSession::empty().with::<EditionSession>();
55+
vortex_alp::initialize(&session);
56+
vortex_datetime_parts::initialize(&session);
57+
vortex_decimal_byte_parts::initialize(&session);
58+
vortex_fastlanes::initialize(&session);
59+
vortex_fsst::initialize(&session);
60+
vortex_onpair::initialize(&session);
61+
vortex_runend::initialize(&session);
62+
vortex_sequence::initialize(&session);
63+
vortex_sparse::initialize(&session);
64+
vortex_zigzag::initialize(&session);
65+
for family in EDITION_FAMILIES {
66+
session.editions().declare_family(family).unwrap();
67+
}
68+
for declaration in EDITION_DECLARATIONS {
69+
session.register_edition(declaration).unwrap();
70+
}
71+
session.enable_edition(CORE_2026_08_3).unwrap();
72+
session
73+
});
74+
4175
fn make_clickbench_window_name() -> ArrayRef {
4276
// A test that's meant to mirror the WindowName column from ClickBench.
4377
let mut values = buffer_mut![-1i32; 65_536];
@@ -76,6 +110,35 @@ mod benchmarks {
76110
.unwrap()
77111
});
78112
}
113+
114+
/// Compresses a canonical `Decimal(12, 2)` column whose values are drawn like those of the
115+
/// golden `decimal_prices` column.
116+
#[divan::bench]
117+
fn btrblocks_decimal(bencher: Bencher) {
118+
let mut rng = StdRng::seed_from_u64(115);
119+
let values: Buffer<i64> = (0..65_536)
120+
.map(|_| rng.random_range(0..10_000_000i64))
121+
.collect();
122+
// NB: the default `core` edition does not permit `vortex.decimal_byte_parts.v2`, so the
123+
// decimal scheme refines to its v1 variant, as in a default write. An unrestricted
124+
// compressor would refine to v2 instead.
125+
let compressor = BtrBlocksCompressorBuilder::from_session(&WRITE_SESSION).build();
126+
bencher
127+
.with_inputs(|| {
128+
(
129+
DecimalArray::new(
130+
values.clone(),
131+
DecimalDType::new(12, 2),
132+
Validity::NonNullable,
133+
)
134+
.into_array(),
135+
WRITE_SESSION.create_execution_ctx(),
136+
)
137+
})
138+
.input_counter(|(array, _)| ItemsCount::new(array.len()))
139+
.input_counter(|(array, _)| BytesCount::of_many::<i64>(array.len()))
140+
.bench_refs(|(array, ctx)| compressor.compress(array, ctx).unwrap());
141+
}
79142
}
80143

81144
#[global_allocator]

0 commit comments

Comments
 (0)