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

dev criterion-cycles-per-byte

measure time with CPU cycles for criterion

1 unstable release

✓ Uses Rust 2018 edition

0.1.1 Sep 27, 2019
0.1.0 Sep 23, 2019
Download history 13/week @ 2019-11-01 25/week @ 2019-11-08 30/week @ 2019-11-15 29/week @ 2019-11-22 107/week @ 2019-11-29 52/week @ 2019-12-06 41/week @ 2019-12-13 8/week @ 2019-12-20 22/week @ 2019-12-27 35/week @ 2020-01-03 69/week @ 2020-01-10 136/week @ 2020-01-17 355/week @ 2020-01-24 322/week @ 2020-01-31 513/week @ 2020-02-07

166 downloads per month
Used in 8 crates

MIT/Apache

5KB
78 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

~11MB
~113K SLoC