criterion-linux-perf 0.1.0

A measurement plugin for Criterion.rs that provides measurements using Linux's perf interface
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented1 out of 4 items with examples
  • Size
  • Source code size: 25.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.21 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 37s Average build duration of successful builds.
  • all releases: 37s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bruceg/criterion-linux-perf
    9 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bruceg

criterion-linux-perf

This is a measurement plugin for Criterion.rs that provides measurements using Linux's perf interface.

Supported Events

criterion-linux-perf uses the perf-event crate and supports a subset of the events provided by that crate. If you require more events than the current selection, please open an issue to request additions.

Example

The following code shows on how to count branches when creating an empty string:

use criterion::{criterion_group, criterion_main, Criterion};
use criterion_linux_perf::{PerfMeasurement, PerfMode};

fn timeit(crit: &mut Criterion<PerfMeasurement>) {
    crit.bench_function("String::new", |b| b.iter(|| String::new()));
    crit.bench_function("String::from", |b| b.iter(|| String::from("")));
}

criterion_group!(
    name = benches;
    config = Criterion::default().with_measurement(PerfMeasurement::new(PerfMode::Branches));
    targets = timeit
);
criterion_main!(benches);

Other Crates

I am aware of one other crate that provides the same functionality, criterion-perf-events. While it provides a much wider coverage of the available perf event types, it depends on perfcnt which only builds on Rust nightly. This crate depends on perf-event, which does not have that limitation.