Feature Flags
none: no features.std(default): uses Rust standard library; disablesno_stdbenchmark(default): enables default benchmark measurement.metrics(optional): production/live metrics (Watch,Timer,stopwatch!).default: convenience feature equal tostd + benchmarkstandard: convenience feature equal tostd + benchmark + metricsminimal: minimal build with core timing only (no default features)all: Activates all features (includes:std + benchmark + metrics)
— See FEATURES DOCUMENTATION for more information.
Installation
Add this to your Cargo.toml:
[]
= "0.8.0"
Standard Features
Enables all standard benchmark features.
[]
# Enables Production & Development.
= { = "0.8.0", = ["standard"] }
Production metrics (std + metrics)
Enable production observability using Watch/Timer or the stopwatch! macro.
Cargo features:
[]
= { = "0.8.0", = ["std", "metrics"] }
Record with Timer (auto-record on drop):
use ;
let watch = new;
// recorded once on drop
let s = &watch.snapshot;
assert!;
Or use the stopwatch! macro:
use ;
let watch = new;
stopwatch!;
assert!;
Disable Default Features
True zero-overhead core timing only.
[]
# Disable default features for true zero-overhead
= { = "0.8.0", = false }
— See FEATURES DOCUMENTATION for more information.
Quick Start
Measure a closure
Use measure() to time any closure and get back (result, Duration).
use measure;
let = measure;
assert_eq!;
println!;
Time an expression with the macro
time! works with any expression and supports async contexts.
use time;
let = time!;
assert!;
Micro-benchmark a code block
Use benchmark_block! to run a block many times and get raw per-iteration durations.
use benchmark_block;
// Default 10_000 iterations
let samples = benchmark_block!;
assert_eq!;
// Explicit iterations
let samples = benchmark_block!;
Macro-benchmark a named expression
Use benchmark! to run a named expression repeatedly and get (last, Vec<Measurement>).
use benchmark;
// Default 10_000 iterations
let = benchmark!;
assert_eq!;
assert_eq!;
// Explicit iterations
let = benchmark!;
assert_eq!;
Named timing + Collector aggregation (std + benchmark)
Record a named measurement and aggregate stats with Collector.
use ;
let collector = new;
let = time_named!;
collector.record;
let stats = collector.stats.unwrap;
println!;
Async timing with await
The macros inline Instant timing when features = ["std", "benchmark"], so awaiting inside works seamlessly.
use time;
async
Collector Statistics
stats::single/1000 ~ 2.44–2.61 µs stats::single/10000 ~ 26.7–29.1 µs stats::all/k10_n1000 ~ 29.4–33.6 µs stats::all/k50_n1000 ~ 148.6–157.1 µs
Array Baseline (no locks)
stats::array/k1_n10000 ~ 17.15–17.90 µs stats::array/k10_n1000 ~ 15.03–16.25 µs
overhead::measure/measure_closure_add time: [X ns .. Y ns .. Z ns]
overhead::time_macro/time_macro_add time: [X ns .. Y ns .. Z ns]
We welcome contributions! Please see CONTRIBUTING.md for guidelines.