forked from jorgecarleitao/arrow2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap_assign_ops.rs
47 lines (40 loc) · 1.77 KB
/
bitmap_assign_ops.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
use criterion::{criterion_group, criterion_main, Criterion};
use arrow2::bitmap::{binary_assign, unary_assign};
use arrow2::bitmap::{Bitmap, MutableBitmap};
fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);
let mut bitmap: MutableBitmap = (0..size).into_iter().map(|x| x % 3 == 0).collect();
c.bench_function(&format!("mutablebitmap not 2^{log2_size}"), |b| {
b.iter(|| {
unary_assign(criterion::black_box(&mut bitmap), |x: u64| !x);
assert!(!bitmap.is_empty());
})
});
let bitmap: Bitmap = (0..size).into_iter().map(|x| x % 3 == 0).collect();
c.bench_function(&format!("bitmap not 2^{log2_size}"), |b| {
b.iter(|| {
let r = !criterion::black_box(&bitmap);
assert!(!r.is_empty());
})
});
let mut lhs: MutableBitmap = (0..size).into_iter().map(|x| x % 3 == 0).collect();
let rhs: Bitmap = (0..size).into_iter().map(|x| x % 4 == 0).collect();
c.bench_function(&format!("mutablebitmap and 2^{log2_size}"), |b| {
b.iter(|| {
binary_assign(criterion::black_box(&mut lhs), &rhs, |x: u64, y| x & y);
assert!(!bitmap.is_empty());
})
});
let lhs: Bitmap = (0..size).into_iter().map(|x| x % 3 == 0).collect();
let rhs: Bitmap = (0..size).into_iter().map(|x| x % 4 == 0).collect();
c.bench_function(&format!("bitmap and 2^{log2_size}"), |b| {
b.iter(|| {
let r = criterion::black_box(&lhs) & &rhs;
assert!(!r.is_empty());
})
});
});
}
criterion_group!(benches, add_benchmark);
criterion_main!(benches);