| 1 | use criterion::{Criterion, Throughput, criterion_group, criterion_main}; |
| 2 | |
| 3 | macro_rules! benchmark { |
| 4 | ($name:tt, $histogram:ident, $c:ident) => { |
| 5 | let mut group = $c.benchmark_group($name); |
| 6 | group.throughput(Throughput::Elements(1)); |
| 7 | group.bench_function("increment/1", |b| b.iter(|| $histogram.increment(1))); |
| 8 | group.bench_function("increment/max", |b| { |
| 9 | b.iter(|| $histogram.increment(u64::MAX)) |
| 10 | }); |
| 11 | group.finish(); |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | fn histogram_u64(c: &mut Criterion) { |
| 16 | let mut histogram = histogram::Histogram::new(7, 64).unwrap(); |
| 17 | benchmark!("histogram/u64", histogram, c); |
| 18 | } |
| 19 | |
| 20 | fn histogram_u32(c: &mut Criterion) { |
| 21 | let mut histogram = histogram::Histogram32::new(7, 64).unwrap(); |
| 22 | benchmark!("histogram/u32", histogram, c); |
| 23 | } |
| 24 | |
| 25 | fn atomic_u64(c: &mut Criterion) { |
| 26 | let histogram = histogram::AtomicHistogram::new(7, 64).unwrap(); |
| 27 | benchmark!("atomic_histogram/u64", histogram, c); |
| 28 | } |
| 29 | |
| 30 | fn atomic_u32(c: &mut Criterion) { |
| 31 | let histogram = histogram::AtomicHistogram32::new(7, 64).unwrap(); |
| 32 | benchmark!("atomic_histogram/u32", histogram, c); |
| 33 | } |
| 34 | |
| 35 | criterion_group!( |
| 36 | benches, |
| 37 | histogram_u64, |
| 38 | histogram_u32, |
| 39 | atomic_u64, |
| 40 | atomic_u32 |
| 41 | ); |
| 42 | criterion_main!(benches); |