1 | use criterion::{criterion_group, Criterion}; |
2 | use plotters::data::Quartiles; |
3 | |
4 | struct Lcg { |
5 | state: u32, |
6 | } |
7 | |
8 | impl Lcg { |
9 | fn new() -> Lcg { |
10 | Lcg { state: 0 } |
11 | } |
12 | } |
13 | |
14 | impl Iterator for Lcg { |
15 | type Item = u32; |
16 | |
17 | fn next(&mut self) -> Option<u32> { |
18 | self.state = self.state.wrapping_mul(1_103_515_245).wrapping_add(12_345); |
19 | self.state %= 1 << 31; |
20 | Some(self.state) |
21 | } |
22 | } |
23 | |
24 | fn quartiles_calc(c: &mut Criterion) { |
25 | let src: Vec<u32> = Lcg::new().take(100000).collect(); |
26 | c.bench_function("data::quartiles_calc" , |b| { |
27 | b.iter(|| { |
28 | Quartiles::new(&src); |
29 | }) |
30 | }); |
31 | } |
32 | |
33 | criterion_group! { |
34 | name = quartiles_group; |
35 | config = Criterion::default().sample_size(10); |
36 | targets = quartiles_calc |
37 | } |
38 | |