-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzonemap_benches.rs
50 lines (44 loc) · 1.59 KB
/
zonemap_benches.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
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
use lever::index::zonemap::ZoneMap;
fn bench_zonemap_selected(c: &mut Criterion) {
c.bench_function("bench_unoptimized", move |b| {
b.iter_batched(
|| {
let customers: Vec<i32> =
vec![vec![1, 0, -1, -2].repeat(500), vec![1, 2, 3, 4].repeat(250)].concat();
let ingestion_data = vec![("customers", customers.as_slice())];
(ZoneMap::from(ingestion_data), customers)
},
|(zm, customers)| {
let (l, r) = zm.scan_range("customers", 4, 4, &*customers);
customers[l..=r].iter().filter(|x| **x >= 4).sum::<i32>()
},
BatchSize::LargeInput,
)
});
}
fn bench_unoptimized(c: &mut Criterion) {
c.bench_function("bench_zonemap_selected", move |b| {
b.iter_batched(
|| {
let customers: Vec<i32> =
vec![vec![1, 0, -1, -2].repeat(500), vec![1, 2, 3, 4].repeat(250)].concat();
let _ingestion_data = vec![("customers", customers.as_slice())];
customers
},
|data| {
data.as_slice()
.into_iter()
.filter(|x| **x >= 4)
.sum::<i32>()
},
BatchSize::LargeInput,
)
});
}
criterion_group! {
name = zonemap_benches;
config = Criterion::default();
targets = bench_zonemap_selected, bench_unoptimized
}
criterion_main!(zonemap_benches);