darwin-kperf-criterion
Criterion benchmarks using Apple hardware performance counters
IntroductionCopy link to this section
darwin-kperf-criterion connects darwin-kperf to Criterion benchmarks. Its HardwareCounter measurement can report retired instructions, CPU cycles, branch mispredictions, or L1 data-cache misses.
Published release: 0.1.0 on crates.io.
InstallationCopy link to this section
cargo add --dev darwin-kperf-criterionConfigure countersCopy link to this section
Pass a HardwareCounter to Criterion's with_measurement method. Use HardwareCounter::instructions() to measure retired instructions, or select another constructor for the counter your benchmark needs. The API documentation includes Criterion setup examples and the available counters.
Hardware counters require macOS on Apple Silicon and root privileges or the com.apple.private.kernel.kpc entitlement. On non-macOS platforms, the crate falls back to wall-clock measurements. Account for that difference when comparing results across platforms.
Custom measurements use events defined by darwin-kperf-events. See the source for the implementation and optional CodSpeed integration.