Skip to content

Commit 28649fb

Browse files
committed
clean up FoR benches
Signed-off-by: Matt Katz <[email protected]>
1 parent dd23ead commit 28649fb

2 files changed

Lines changed: 19 additions & 66 deletions

File tree

‎encodings/fastlanes/benches/for_decode.rs‎

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

4-
//! Compare decoding a FoR array with one reference against one with a reference per 1024-element
5-
//! chunk, over both a primitive child and a BitPacked child, which decode through a fused unpack.
6-
//!
7-
//! Every chunk spans the same range of values, so both encodings pack at the same bit width and
8-
//! the difference between them is the cost of the per-chunk references.
4+
//! Benchmarks decoding a FoR array with a reference per 1024-element chunk, over a primitive child
5+
//! and over a BitPacked child. An unsigned BitPacked child decodes through a fused unpack, and a
6+
//! signed one through BitPacked decoding followed by adding the references in place.
97
//!
108
//! Every benchmark carries `#[cpu_features]`, so it is measured on each walltime CPU-feature leg
119
//! rather than in simulation: the loops under test are auto-vectorized, so the build decides
@@ -57,18 +55,10 @@ fn values<T: NativePType + TryFrom<usize>>(len: usize) -> Buffer<T> {
5755
.collect()
5856
}
5957

60-
fn for_array<T: NativePType + TryFrom<usize>>(
61-
len: usize,
62-
chunked: bool,
63-
bitpacked: bool,
64-
) -> ArrayRef {
58+
fn for_array<T: NativePType + TryFrom<usize>>(len: usize, bitpacked: bool) -> ArrayRef {
6559
let mut ctx = SESSION.create_execution_ctx();
6660
let array = PrimitiveArray::new(values::<T>(len), Validity::NonNullable);
67-
let for_array = if chunked {
68-
FoR::encode_chunked(array, &mut ctx).unwrap()
69-
} else {
70-
FoR::encode(array, &mut ctx).unwrap()
71-
};
61+
let for_array = FoR::encode_chunked(array, &mut ctx).unwrap();
7262
if !bitpacked {
7363
return for_array.into_array();
7464
}
@@ -78,40 +68,23 @@ fn for_array<T: NativePType + TryFrom<usize>>(
7868
.into_array()
7969
}
8070

81-
fn run<T: NativePType + TryFrom<usize>>(
82-
bencher: Bencher,
83-
bytes: usize,
84-
chunked: bool,
85-
bitpacked: bool,
86-
) {
71+
fn run<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize, bitpacked: bool) {
8772
let len = bytes / size_of::<T>();
88-
let array = for_array::<T>(len, chunked, bitpacked);
73+
let array = for_array::<T>(len, bitpacked);
8974
bencher
9075
.counter(ItemsCount::new(len))
9176
.with_inputs(|| (&array, SESSION.create_execution_ctx()))
9277
.bench_refs(|(array, ctx)| (*array).clone().execute::<PrimitiveArray>(ctx).unwrap());
9378
}
9479

95-
#[vortex_bench_support::cpu_features]
96-
#[divan::bench(types = [i64], args = INPUT_BYTES)]
97-
fn decode<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
98-
run::<T>(bencher, bytes, false, false);
99-
}
100-
10180
#[vortex_bench_support::cpu_features]
10281
#[divan::bench(types = [i64], args = INPUT_BYTES)]
10382
fn decode_chunked<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
104-
run::<T>(bencher, bytes, true, false);
83+
run::<T>(bencher, bytes, false);
10584
}
10685

10786
#[vortex_bench_support::cpu_features]
108-
#[divan::bench(types = [i64], args = INPUT_BYTES)]
109-
fn decode_bitpacked<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
110-
run::<T>(bencher, bytes, false, true);
111-
}
112-
113-
#[vortex_bench_support::cpu_features]
114-
#[divan::bench(types = [i64], args = INPUT_BYTES)]
87+
#[divan::bench(types = [u32, i64], args = INPUT_BYTES)]
11588
fn decode_bitpacked_chunked<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
116-
run::<T>(bencher, bytes, true, true);
89+
run::<T>(bencher, bytes, true);
11790
}

‎encodings/fastlanes/benches/for_encode.rs‎

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

4-
//! Compare `FoR::encode`, which subtracts one reference from every value, against
5-
//! `FoR::encode_chunked`, which subtracts a reference per 1024-element chunk.
4+
//! Benchmarks `FoR::encode_chunked`, which subtracts a reference per 1024-element chunk, with and
5+
//! without nulls.
66
//!
77
//! Every benchmark carries `#[cpu_features]`, so it is measured on each walltime CPU-feature leg
88
//! rather than in simulation: the loops under test are auto-vectorized, so the build decides
@@ -17,15 +17,12 @@ use std::sync::LazyLock;
1717
use divan::Bencher;
1818
use divan::counter::ItemsCount;
1919
use mimalloc::MiMalloc;
20-
use vortex_array::ExecutionCtx;
2120
use vortex_array::VortexSessionExecute;
2221
use vortex_array::arrays::PrimitiveArray;
2322
use vortex_array::dtype::NativePType;
2423
use vortex_array::validity::Validity;
2524
use vortex_buffer::Buffer;
26-
use vortex_error::VortexResult;
2725
use vortex_fastlanes::FoR;
28-
use vortex_fastlanes::FoRArray;
2926
use vortex_session::VortexSession;
3027

3128
#[global_allocator]
@@ -44,8 +41,6 @@ static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
4441
/// Bytes of values per input array.
4542
const INPUT_BYTES: &[usize] = &[512 * 1024];
4643

47-
type Encode = fn(PrimitiveArray, &mut ExecutionCtx) -> VortexResult<FoRArray>;
48-
4944
/// Values that step up by 1000 every chunk, with a small spread within each chunk.
5045
fn values<T: NativePType + TryFrom<usize>>(len: usize) -> Buffer<T> {
5146
(0..len)
@@ -65,42 +60,27 @@ fn validity(len: usize, nullable: bool) -> Validity {
6560
}
6661
}
6762

68-
fn run<T: NativePType + TryFrom<usize>>(
69-
bencher: Bencher,
70-
bytes: usize,
71-
nullable: bool,
72-
encode: Encode,
73-
) {
63+
fn run<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize, nullable: bool) {
7464
let len = bytes / size_of::<T>();
7565
let buffer = values::<T>(len);
7666
let validity = validity(len, nullable);
7767
bencher
7868
.counter(ItemsCount::new(len))
79-
// A fresh array per iteration, so `FoR::encode` can't reuse a cached `Min` statistic.
69+
// `encode_chunked` takes the array by value, so each iteration encodes a fresh one.
8070
.with_inputs(|| PrimitiveArray::new(buffer.clone(), validity.clone()))
81-
.bench_local_values(|array| encode(array, &mut SESSION.create_execution_ctx()).unwrap());
82-
}
83-
84-
#[vortex_bench_support::cpu_features]
85-
#[divan::bench(types = [i64], args = INPUT_BYTES)]
86-
fn encode<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
87-
run::<T>(bencher, bytes, false, FoR::encode);
71+
.bench_local_values(|array| {
72+
FoR::encode_chunked(array, &mut SESSION.create_execution_ctx()).unwrap()
73+
});
8874
}
8975

9076
#[vortex_bench_support::cpu_features]
9177
#[divan::bench(types = [i64], args = INPUT_BYTES)]
9278
fn encode_chunked<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
93-
run::<T>(bencher, bytes, false, FoR::encode_chunked);
94-
}
95-
96-
#[vortex_bench_support::cpu_features]
97-
#[divan::bench(types = [i64], args = INPUT_BYTES)]
98-
fn encode_nullable<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
99-
run::<T>(bencher, bytes, true, FoR::encode);
79+
run::<T>(bencher, bytes, false);
10080
}
10181

10282
#[vortex_bench_support::cpu_features]
10383
#[divan::bench(types = [i64], args = INPUT_BYTES)]
10484
fn encode_chunked_nullable<T: NativePType + TryFrom<usize>>(bencher: Bencher, bytes: usize) {
105-
run::<T>(bencher, bytes, true, FoR::encode_chunked);
85+
run::<T>(bencher, bytes, true);
10686
}

0 commit comments

Comments
 (0)