6 releases (3 breaking)

0.6.0 Nov 25, 2023
0.5.0 May 28, 2023
0.4.0 Dec 16, 2022
0.1.3 Dec 16, 2022
0.1.1 Sep 27, 2019

#34 in Profiling

Download history 976/week @ 2024-01-01 936/week @ 2024-01-08 1567/week @ 2024-01-15 988/week @ 2024-01-22 1576/week @ 2024-01-29 1468/week @ 2024-02-05 1280/week @ 2024-02-12 1829/week @ 2024-02-19 1257/week @ 2024-02-26 1252/week @ 2024-03-04 1105/week @ 2024-03-11 1086/week @ 2024-03-18 1010/week @ 2024-03-25 1140/week @ 2024-04-01 1224/week @ 2024-04-08 1419/week @ 2024-04-15

4,895 downloads per month
Used in fewer than 25 crates

MIT/Apache

9KB
106 lines

criterion-cycles-per-byte

GITHUB Crates.io docs

CyclesPerByte measures ticks using the CPU read time-stamp counter instruction.

Architecture Instruction
x86 rdtsc
x86_64 rdtsc
aarch64 (running GNU/Linux kernel) pmccntr
loongarch64 rdtime.d

Warning This crate measures clock ticks rather than cycles. It will not provide accurate results on modern machines unless you calculate the ratio of ticks to cycles and take steps to ensure that that ratio remains consistent.

Warning In case you're planning to use this library on an aarch64 target, running GNU/Linux kernel, I advise you to read src/lib.rs#L61-L68.


# 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);

Note I am not the original writer but am maintaining this crate because it is still being used in several places. I plan to do version updates and bug fixes as necessary but not to add features or attempt fix the (potentially intractable) problems with this method of measurement.

Compatibility

Criterion version Cycles Per Byte Version
0.5 0.6
0.4 0.4

Dependencies

~8–19MB
~253K SLoC