-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathpipeline_v2_bitpacking_basic.rs
More file actions
75 lines (60 loc) · 2.38 KB
/
Copy pathpipeline_v2_bitpacking_basic.rs
File metadata and controls
75 lines (60 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#![allow(clippy::unwrap_used)]
#![allow(unexpected_cfgs)]
use divan::Bencher;
use mimalloc::MiMalloc;
use rand::prelude::StdRng;
use rand::{Rng, SeedableRng};
use vortex_array::arrays::PrimitiveArray;
use vortex_fastlanes::BitPackedArray;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
pub fn main() {
divan::main();
}
// Cross product of NUM_ELEMENTS and VALIDITY_PCT.
const BENCH_PARAMS: &[(usize, f64)] = &[
(1_000, 0.5),
(1_000, 1.0),
(10_000, 0.5),
(10_000, 1.0),
(100_000, 0.5),
(100_000, 1.0),
];
#[divan::bench(args = BENCH_PARAMS)]
fn bitpack_pipeline_unpack(bencher: Bencher, (num_elements, validity_pct): (usize, f64)) {
bencher
.with_inputs(|| {
let mut rng = StdRng::seed_from_u64(42);
// Create array with randomized validity.
// Keep values small enough to fit in the bit width (0-1023 for 10 bits).
let values = (0..num_elements).map(|_| {
let is_valid = rng.random_bool(validity_pct);
is_valid.then(|| rng.random_range(0u32..1024))
});
let primitive = PrimitiveArray::from_option_iter(values).to_array();
// Encode with 10-bit width (supports values up to 1023).
let bitpacked = BitPackedArray::encode(&primitive, 10).unwrap();
bitpacked.to_array()
})
.bench_local_values(|array| array.execute().unwrap());
}
#[divan::bench(args = BENCH_PARAMS)]
fn bitpack_canonical_unpack(bencher: Bencher, (num_elements, validity_pct): (usize, f64)) {
bencher
.with_inputs(|| {
let mut rng = StdRng::seed_from_u64(42);
// Create array with randomized validity.
// Keep values small enough to fit in the bit width (0-1023 for 10 bits).
let values = (0..num_elements).map(|_| {
let is_valid = rng.random_bool(validity_pct);
is_valid.then(|| rng.random_range(0u32..1024))
});
let primitive = PrimitiveArray::from_option_iter(values).to_array();
// Encode with 10-bit width (supports values up to 1023).
let bitpacked = BitPackedArray::encode(&primitive, 10).unwrap();
bitpacked.to_array()
})
.bench_local_values(|array| array.to_canonical());
}