-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathdict_mask.rs
More file actions
74 lines (68 loc) · 1.99 KB
/
dict_mask.rs
File metadata and controls
74 lines (68 loc) · 1.99 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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#![expect(clippy::unwrap_used)]
use divan::Bencher;
use rand::RngExt;
use rand::SeedableRng;
use rand::rngs::StdRng;
use vortex_array::IntoArray;
use vortex_array::RecursiveCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::DictArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::builtins::ArrayBuiltins;
use vortex_mask::Mask;
use vortex_session::VortexSession;
fn main() {
divan::main();
}
fn filter_mask(len: usize, fraction_masked: f64, rng: &mut StdRng) -> Mask {
let indices = (0..len)
.filter(|_| rng.random_bool(fraction_masked))
.collect::<Vec<usize>>();
Mask::from_indices(len, indices)
}
#[divan::bench(args = [
(0.9, 0.9),
(0.9, 0.5),
(0.9, 0.1),
(0.9, 0.01),
(0.5, 0.9),
(0.5, 0.5),
(0.5, 0.1),
(0.5, 0.01),
(0.1, 0.9),
(0.1, 0.5),
(0.1, 0.1),
(0.1, 0.01),
(0.01, 0.9),
(0.01, 0.5),
(0.01, 0.1),
(0.01, 0.01),
])]
fn bench_dict_mask(bencher: Bencher, (fraction_valid, fraction_masked): (f64, f64)) {
let mut rng = StdRng::seed_from_u64(0);
let len = 65_535;
let codes = PrimitiveArray::from_iter((0..len).map(|_| {
if rng.random_bool(fraction_valid) {
1u64
} else {
0u64
}
}))
.into_array();
let values = PrimitiveArray::from_option_iter([None, Some(42i32)]).into_array();
let array = DictArray::try_new(codes, values).unwrap().into_array();
let filter_mask = filter_mask(len, fraction_masked, &mut rng);
let session = VortexSession::empty();
bencher
.with_inputs(|| (&array, &filter_mask, session.create_execution_ctx()))
.bench_refs(|(array, filter_mask, ctx)| {
array
.clone()
.mask(filter_mask.clone().into_array())
.unwrap()
.execute::<RecursiveCanonical>(ctx)
.unwrap()
});
}