#criterion #byte #cpu #per

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

#58 in Profiling


Used in 3 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

~6MB
~107K SLoC