#criterion #byte #cpu #per #measure-time

dev criterion-cycles-per-byte

measure time with CPU cycles for criterion

2 releases

new 0.1.2 Sep 12, 2020
0.1.1 Sep 27, 2019
0.1.0 Sep 23, 2019

#27 in Visualization

Download history 1368/week @ 2020-05-29 1536/week @ 2020-06-05 981/week @ 2020-06-12 748/week @ 2020-06-19 827/week @ 2020-06-26 896/week @ 2020-07-03 1176/week @ 2020-07-10 994/week @ 2020-07-17 866/week @ 2020-07-24 800/week @ 2020-07-31 832/week @ 2020-08-07 989/week @ 2020-08-14 885/week @ 2020-08-21 960/week @ 2020-08-28 800/week @ 2020-09-04 178/week @ 2020-09-11

3,788 downloads per month
Used in less than 6 crates

MIT/Apache

7KB
77 lines


lib.rs:

CyclesPerByte measures clock cycles using the x86 or x86_64 rdtsc instruction.

# fn fibonacci_slow(_: usize) {}
# fn fibonacci_fast(_: usize) {}
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use criterion_cycles_per_byte::CyclesPerByte;

fn bench(c: &mut Criterion<CyclesPerByte>) {
    let mut group = c.benchmark_group("fibonacci");

    for i in 0..20 {
        group.bench_function(BenchmarkId::new("slow", i), |b| b.iter(|| fibonacci_slow(i)));
        group.bench_function(BenchmarkId::new("fast", i), |b| b.iter(|| fibonacci_fast(i)));
    }

    group.finish()
}

criterion_group!(
    name = my_bench;
    config = Criterion::default().with_measurement(CyclesPerByte);
    targets = bench
);
criterion_main!(my_bench);

Dependencies

~12MB
~189K SLoC