Expand description
A zero-dependency, high-performance time measurement library for Rust.
This library provides nanosecond precision benchmarking with true zero-overhead when disabled. Designed as a foundational primitive that other libraries can depend on without concern for bloat, version conflicts, or performance impact.
§Features
- Zero Dependencies: Built using only the Rust standard library
- True Zero Overhead: When disabled, all code compiles away completely
- Thread Safe: Core functions are pure, with optional thread-safe collection
- Async Compatible: Works seamlessly with any async runtime
- Simple API: Just four functions and two macros
§Quick Start
use benchmark::{measure, time};
// Measure a function
let (result, duration) = measure(|| {
// Some expensive computation
42
});
println!("Computation took {} nanoseconds", duration.as_nanos());
// Use the macro for convenience
fn expensive_function() -> i32 { 2 + 2 }
let (result, duration) = time!(expensive_function());
assert_eq!(result, 4);
Macros§
- time
- Times an expression and returns (result, duration).
- time_
named - Times an expression with a name and returns (result, measurement).
Structs§
- Collector
- A thread-safe collector for measurements.
- Duration
- A duration represented in nanoseconds.
- Measurement
- A single time measurement.
- Stats
- Basic statistics for a set of measurements.
Functions§
- measure
- Measures the execution time of a function.
- measure_
named - Measures the execution time of a function with a name.