Skip to content
Open
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
32 changes: 15 additions & 17 deletions encodings/alp/benches/alp_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#![expect(clippy::unwrap_used)]

use std::sync::LazyLock;

use divan::Bencher;
use rand::RngExt;
use rand::SeedableRng as _;
Expand All @@ -14,13 +16,14 @@ use vortex_alp::alp_encode;
use vortex_alp::decompress_into_array;
use vortex_array::Canonical;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::dtype::NativePType;
use vortex_array::session::ArraySession;
use vortex_array::validity::Validity;
use vortex_buffer::Buffer;
use vortex_buffer::buffer;
use vortex_session::VortexSession;

fn main() {
divan::main();
Expand Down Expand Up @@ -48,6 +51,9 @@ const BENCH_ARGS: &[(usize, f64, f64)] = &[
(10_000, 0.1, 1.0),
];

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

#[divan::bench(types = [f32, f64], args = BENCH_ARGS)]
fn compress_alp<T: ALPFloat + NativePType>(bencher: Bencher, args: (usize, f64, f64)) {
let (n, fraction_patch, fraction_valid) = args;
Expand All @@ -68,14 +74,9 @@ fn compress_alp<T: ALPFloat + NativePType>(bencher: Bencher, args: (usize, f64,
let values = values.freeze();
let array = PrimitiveArray::new(values, validity);

bencher.with_inputs(|| &array).bench_values(|array| {
alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
})
bencher
.with_inputs(|| (&array, SESSION.create_execution_ctx()))
.bench_values(|(array, mut ctx)| alp_encode(array.as_view(), None, &mut ctx).unwrap())
}

#[divan::bench(types = [f32, f64], args = BENCH_ARGS)]
Expand All @@ -102,10 +103,10 @@ fn decompress_alp<T: ALPFloat + NativePType>(bencher: Bencher, args: (usize, f64
alp_encode(
PrimitiveArray::new(Buffer::copy_from(&values), validity.clone()).as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
&mut SESSION.create_execution_ctx(),
)
.unwrap(),
LEGACY_SESSION.create_execution_ctx(),
SESSION.create_execution_ctx(),
)
})
.bench_values(|(v, mut ctx)| decompress_into_array(v, &mut ctx));
Expand Down Expand Up @@ -143,7 +144,7 @@ fn compress_rd<T: ALPRDFloat + NativePType>(bencher: Bencher, args: (usize, f64)
let encoder = RDEncoder::new(primitive.as_slice::<T>());

bencher
.with_inputs(|| (&primitive, &encoder, LEGACY_SESSION.create_execution_ctx()))
.with_inputs(|| (&primitive, &encoder, SESSION.create_execution_ctx()))
.bench_refs(|(primitive, encoder, ctx)| encoder.encode(primitive.as_view(), ctx))
}

Expand All @@ -152,12 +153,9 @@ fn decompress_rd<T: ALPRDFloat + NativePType>(bencher: Bencher, args: (usize, f6
let (n, fraction_patch) = args;
let primitive = make_rd_array::<T>(n, fraction_patch);
let encoder = RDEncoder::new(primitive.as_slice::<T>());
let encoded = encoder.encode(
primitive.as_view(),
&mut LEGACY_SESSION.create_execution_ctx(),
);
let encoded = encoder.encode(primitive.as_view(), &mut SESSION.create_execution_ctx());

bencher
.with_inputs(|| (&encoded, LEGACY_SESSION.create_execution_ctx()))
.with_inputs(|| (&encoded, SESSION.create_execution_ctx()))
.bench_refs(|(encoded, ctx)| (**encoded).clone().into_array().execute::<Canonical>(ctx));
}
20 changes: 10 additions & 10 deletions encodings/experimental/onpair/benches/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ fn canonicalize_to_varbinview(bencher: Bencher, case: (Shape, usize)) {
let (shape, n) = case;
let arr = compress(n, shape);
bencher
.with_inputs(|| arr.clone().into_array())
.bench_local_values(|arr| {
let mut ctx = SESSION.create_execution_ctx();
.with_inputs(|| (arr.clone().into_array(), SESSION.create_execution_ctx()))
.bench_local_values(|(arr, mut ctx)| {
divan::black_box(
arr.execute::<VarBinViewArray>(&mut ctx)
.unwrap_or_else(|e| panic!("canonicalize failed: {e}")),
Expand All @@ -234,13 +233,14 @@ fn filter_share_dict(bencher: Bencher, case: (Shape, usize)) {
let (shape, n) = case;
let arr = compress(n, shape);
let mask = Mask::from_iter((0..n).map(|i| i % 7 == 0));
bencher.bench_local(|| {
let mut ctx = SESSION.create_execution_ctx();
let result = <OnPair as FilterKernel>::filter(arr.as_view(), &mask, &mut ctx)
.unwrap()
.unwrap();
divan::black_box(result);
});
bencher
.with_inputs(|| SESSION.create_execution_ctx())
.bench_local_values(|mut ctx| {
let result = <OnPair as FilterKernel>::filter(arr.as_view(), &mask, &mut ctx)
.unwrap()
.unwrap();
divan::black_box(result);
});
}

fn main() {
Expand Down
10 changes: 8 additions & 2 deletions encodings/fastlanes/benches/bitpack_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,39 @@
#![expect(clippy::unwrap_used)]
#![expect(clippy::cast_possible_truncation)]

use std::sync::LazyLock;

use divan::Bencher;
use divan::counter::ItemsCount;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::BoolArray;
use vortex_array::arrays::ConstantArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::scalar_fn::fns::operators::Operator;
use vortex_array::session::ArraySession;
use vortex_array::validity::Validity;
use vortex_buffer::BufferMut;
use vortex_fastlanes::BitPackedData;
use vortex_session::VortexSession;

fn main() {
divan::main();
}

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

const LENS: &[usize] = &[1024, 64 * 1024];
const BIT_WIDTHS: &[u8] = &[4, 16];

/// Build a packed array of varied in-range values, plus an out-of-range constant RHS for
/// the fast-path benches.
fn build_inputs<const BW: u8>(len: usize) -> (ArrayRef, ArrayRef, ExecutionCtx) {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut ctx = SESSION.create_execution_ctx();
let buf: BufferMut<u32> = (0..len).map(|i| (i as u32) % (1 << BW)).collect();
let array = BitPackedData::encode(
&PrimitiveArray::new(buf.freeze(), Validity::NonNullable).into_array(),
Expand Down
10 changes: 8 additions & 2 deletions encodings/fastlanes/benches/bitpack_compare_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#![expect(clippy::unwrap_used)]
#![expect(clippy::cast_possible_truncation)]

use std::sync::LazyLock;

use divan::Bencher;
use divan::counter::ItemsCount;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::BoolArray;
use vortex_array::arrays::ConstantArray;
Expand All @@ -26,14 +27,19 @@ use vortex_array::builtins::ArrayBuiltins;
use vortex_array::dtype::NativePType;
use vortex_array::scalar::Scalar;
use vortex_array::scalar_fn::fns::operators::Operator;
use vortex_array::session::ArraySession;
use vortex_array::validity::Validity;
use vortex_buffer::BufferMut;
use vortex_fastlanes::BitPackedData;
use vortex_session::VortexSession;

fn main() {
divan::main();
}

static SESSION: LazyLock<VortexSession> =
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());

/// Number of elements per benchmarked array (64 full FastLanes blocks).
const LEN: usize = 64 * 1024;

Expand Down Expand Up @@ -62,7 +68,7 @@ impl_bench_int!(u8, u16, u32, u64, i8, i16, i32, i64);
/// Encode `LEN` in-range values of type `T` at the given bit width, returning the packed array, a
/// mid-range constant to compare against, and an execution context.
fn setup<T: BenchInt>(width: usize) -> (ArrayRef, ArrayRef, ExecutionCtx) {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut ctx = SESSION.create_execution_ctx();
let cap = 1u64 << width;
let buf: BufferMut<T> = (0..LEN)
.map(|i| T::from_counter((i as u64) % cap))
Expand Down
Loading
Loading