Skip to main content

Crate kevy_bench

Crate kevy_bench 

Source
Expand description

kevy-bench — a pure-Rust micro-benchmark harness. Zero dependencies.

kevy is 0-dependency by policy, so we cannot pull criterion. This is the self-hosted equivalent, used by two callers:

  • per-crate exploration benches (examples/bench_*.rs) — compare two implementations head-to-head and print a speedup ratio. This ratio is the evidence the dep/std self-host evaluation is gated on (“if the candidate isn’t ≥ N× the incumbent, don’t self-host it”).
  • per-crate regression gates (tests/perf_gate.rs) — assert a hot path stays under a documented budget (see time_median).

§Why the ratio survives a loaded host

The campaign that birthed this crate could not get a clean full-system throughput number because the dev host is permanently busy. The escape is to measure components, not the whole server: run the variants back-to-back in one process. Both pay the same contention in the same window, so the absolute ns drifts with load but the ratio between them holds. Treat median_ns as relative, not absolute, unless the host is known idle.

§Method

Each sample times inner iterations of the closure and divides, so the per-op figure isn’t swamped by Instant::now() overhead (~tens of ns) for sub-microsecond work. We report the median sample (robust to the occasional scheduler hiccup) plus p95 and min.

use kevy_bench::{bench, black_box};

let s = bench(50, 1000, || { black_box(1u64 + black_box(2)); });
assert!(s.median_ns < 1_000); // trivial add is nanoseconds

Structs§

Stats
Per-operation timing summary, in nanoseconds. See bench().

Functions§

bench
Run op and return per-operation timing stats.
black_box
Re-exported so benches can fence the optimizer without importing std::hint. An identity function that hints to the compiler to be maximally pessimistic about what black_box could do.
compare
Print both timings and the candidate’s speedup over the baseline (by median).
time_median
Median wall-clock time of a single op call over iters runs.