pub struct SubMsTimer { /* private fields */ }Expand description
Autostart stopwatch with named checkpoints. Not thread-safe; use one per task or synchronise externally.
Implementations§
Source§impl SubMsTimer
impl SubMsTimer
Sourcepub fn nanos_now() -> u64
pub fn nanos_now() -> u64
Single source of truth for monotonic-clock reads across the
subms harness. Returns nanoseconds since a process-local epoch
(snapshotted on first call); meaningful only as a delta against
another nanos_now() reading.
Prefer SubMsTimer::tick + SubMsTick::elapsed_ns in hot
loops - it’s one fewer atomic load + one fewer arithmetic op
because we don’t normalise against the process epoch on each
call.
Sourcepub fn tick() -> SubMsTick
pub fn tick() -> SubMsTick
Snapshot the monotonic clock for the “start tick / do work /
read delta” pattern. Recipes use this inside their bench loops
instead of std::time::Instant::now(). Cost is identical to a
raw Instant::now() (the return is a #[repr(transparent)]
wrapper).
Sourcepub fn measure_ns<F, T>(f: F) -> (T, u64)where
F: FnOnce() -> T,
pub fn measure_ns<F, T>(f: F) -> (T, u64)where
F: FnOnce() -> T,
Time a closure. Returns the closure result and elapsed nanoseconds. Convenient when the call is on the hot path and the caller doesn’t care about retaining a tick handle.
Sourcepub fn unnamed() -> SubMsTimer
pub fn unnamed() -> SubMsTimer
Autostart unnamed timer.
Sourcepub fn new(name: &str) -> SubMsTimer
pub fn new(name: &str) -> SubMsTimer
Autostart timer with a display name (printed in the header).
Sourcepub fn start(&mut self) -> &mut SubMsTimer
pub fn start(&mut self) -> &mut SubMsTimer
Reset to t=0 and clear all checkpoints.
Sourcepub fn reset(&mut self) -> &mut SubMsTimer
pub fn reset(&mut self) -> &mut SubMsTimer
Alias of start.
Sourcepub fn mark(&mut self, label: &str) -> u64
pub fn mark(&mut self, label: &str) -> u64
Record a checkpoint with the given label. Returns the elapsed-since-start ns.
Sourcepub fn lap(&mut self, label: &str) -> u64
pub fn lap(&mut self, label: &str) -> u64
Alias of mark - emphasises “split / next leg” semantics.
Sourcepub fn stop(&mut self, label: &str) -> u64
pub fn stop(&mut self, label: &str) -> u64
Final checkpoint; the timer stops accumulating after this.
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
true after stop is called.
Sourcepub fn elapsed_ns(&self) -> u64
pub fn elapsed_ns(&self) -> u64
Elapsed since start. Frozen at stop-time if stopped.