forked from jorgecarleitao/arrow2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap.rs
76 lines (65 loc) · 2.33 KB
/
bitmap.rs
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
76
use std::iter::FromIterator;
use criterion::{criterion_group, criterion_main, Criterion};
use arrow2::bitmap::*;
fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);
let bitmap2 = Bitmap::from_iter((0..size).into_iter().map(|x| x % 3 == 0));
c.bench_function(&format!("bitmap extend aligned 2^{log2_size}"), |b| {
let mut bitmap1 = MutableBitmap::new();
b.iter(|| {
bitmap1.extend_from_bitmap(&bitmap2);
bitmap1.clear();
})
});
c.bench_function(&format!("bitmap extend unaligned 2^{log2_size}"), |b| {
let mut bitmap1 = MutableBitmap::with_capacity(1);
b.iter(|| {
bitmap1.push(true);
bitmap1.extend_from_bitmap(&bitmap2);
bitmap1.clear();
})
});
c.bench_function(
&format!("bitmap extend_constant aligned 2^{log2_size}"),
|b| {
let mut bitmap1 = MutableBitmap::new();
b.iter(|| {
bitmap1.extend_constant(size, true);
bitmap1.clear();
})
},
);
c.bench_function(
&format!("bitmap extend_constant unaligned 2^{log2_size}"),
|b| {
let mut bitmap1 = MutableBitmap::with_capacity(1);
b.iter(|| {
bitmap1.push(true);
bitmap1.extend_constant(size, true);
bitmap1.clear();
})
},
);
let iter = (0..size)
.into_iter()
.map(|x| x % 3 == 0)
.collect::<Vec<_>>();
c.bench_function(&format!("bitmap from_trusted_len 2^{log2_size}"), |b| {
b.iter(|| {
MutableBitmap::from_trusted_len_iter(iter.iter().copied());
})
});
c.bench_function(
&format!("bitmap extend_from_trusted_len_iter 2^{log2_size}"),
|b| {
b.iter(|| {
let mut a = MutableBitmap::from(&[true]);
a.extend_from_trusted_len_iter(iter.iter().copied());
})
},
);
});
}
criterion_group!(benches, add_benchmark);
criterion_main!(benches);