std-method
Instant::elapsed: measure a local operation
Read the current monotonic clock and compute elapsed time since the stored reading. Use actual measurements for benchmarks; elapsed values are workload and platform dependent. This fixture checks only the result type, not an exact speed or a minimum duration. Expected stdout (not executed): measurement recorded Common mistake: Asserting an exact duration for an operation or a sleep.
Formal Syntax & Structure
rust syntaxrust
start.elapsed() -> DurationWorking Example
Example Snippetrust
fn main() { use std::time::{Duration, Instant}; let start = Instant::now(); let elapsed: Duration = start.elapsed(); let _ = elapsed.as_nanos(); println!("measurement recorded");}