pub struct Timer { /* private fields */ }Expand description
A simple stopwatch timer that supports pause and resume.
Direct port from C++ Timer.h. The timer starts immediately on construction
(unless start_paused is true). Use pause() and resume() any number
of times; elapsed() returns the total time spent unpaused.
§Examples
use clipper2_rust::utils::timer::Timer;
let timer = Timer::new(false);
// ... do work ...
let elapsed = timer.elapsed();
println!("Took {}", Timer::format_duration(elapsed));Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new(start_paused: bool) -> Self
pub fn new(start_paused: bool) -> Self
Create a new timer. If start_paused is false, the timer starts immediately.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Return the total elapsed duration (excluding paused intervals).
If the timer is currently running, includes time since last resume. If the timer is paused, returns accumulated time only.
Sourcepub fn elapsed_nanos(&self) -> u128
pub fn elapsed_nanos(&self) -> u128
Return elapsed time in nanoseconds.
Direct port from C++ elapsed_nano().
Sourcepub fn format_duration(dur: Duration) -> String
pub fn format_duration(dur: Duration) -> String
Format a duration as a human-readable string.
Direct port from C++ elapsed_str().
Automatically selects appropriate units (microsecs, millisecs, secs).
Sourcepub fn elapsed_str(&self) -> String
pub fn elapsed_str(&self) -> String
Return elapsed time as a human-readable string.