Skip to main content

Crate aatxe_bench

Crate aatxe_bench 

Source
Expand description

§aatxe-bench

Authoring API + JSON emitter for aatxe-compatible Rust microbenchmarks.

§Quick start

use aatxe_bench::{bench, Suite};

fn main() {
    let mut suite = Suite::new("my-service");
    bench(&mut suite, "parse_phone", || {
        let _ = parse_phone("+34 612 345 678");
    });
    suite.emit_stdout();
}

Running the binary that calls suite.emit_stdout() prints a fully-formed aatxe_core::types::RunReport JSON, which aatxe run --lang rust ingests directly.

§Why a builder, not #[bench]?

The stable Rust toolchain does not ship #[bench]. Criterion is the standard alternative but introduces a heavy dependency tree and a HTML-report-centric flow. Aatxe-bench instead exposes a small builder that integrates cleanly with cargo run --release — predictable, statically-typed, and trivial to embed in CI.

The sampling loop mirrors the JS authoring API:

  • warmup iterations excluded from the measurement;
  • adaptive sampling that stops once the CV drops below Options::target_cv or the time budget expires or Options::max_iterations is hit;
  • automatic batch sizing for sub-µs operations.

Structs§

Options
Per-bench tuning knobs. Defaults match the JS / aatxe-core defaults so a service can swap between languages without changing its CI gate.
Suite
Collection of benches that will be emitted as a single RunReport.

Enums§

BatchSize

Functions§

bench
Convenience wrapper that uses default Options and a synthetic file tag.
black_box
Re-exported so bench authors can use aatxe_bench::black_box; without an extra std::hint import. Wrapping a value with black_box prevents LLVM from constant-folding or DCE-ing the benched expression. An identity function that hints to the compiler to be maximally pessimistic about what black_box could do.
keep
Defeat dead-code elimination on a benched expression. Returns v unchanged so it can be chained inline: