pub struct Stopwatch { /* private fields */ }
Expand description
A simple stopwatch for measuring elapsed time.
The stopwatch starts automatically upon creation.
§Examples
use khora_core::utils::timer::Stopwatch;
use std::thread;
use std::time::Duration;
let watch = Stopwatch::new();
thread::sleep(Duration::from_millis(50));
let elapsed_ms = watch.elapsed_ms().unwrap_or(0);
assert!(elapsed_ms >= 50);
Implementations§
Source§impl Stopwatch
impl Stopwatch
Sourcepub fn elapsed(&self) -> Option<Duration>
pub fn elapsed(&self) -> Option<Duration>
Returns the elapsed time since the stopwatch was created.
Returns None
if the stopwatch was not properly initialized.
Sourcepub fn elapsed_ms(&self) -> Option<u64>
pub fn elapsed_ms(&self) -> Option<u64>
Returns the elapsed time in whole milliseconds.
Sourcepub fn elapsed_us(&self) -> Option<u64>
pub fn elapsed_us(&self) -> Option<u64>
Returns the elapsed time in whole microseconds.
Sourcepub fn elapsed_secs_f64(&self) -> Option<f64>
pub fn elapsed_secs_f64(&self) -> Option<f64>
Returns the elapsed time in fractional seconds as an f64
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Stopwatch
impl RefUnwindSafe for Stopwatch
impl Send for Stopwatch
impl Sync for Stopwatch
impl Unpin for Stopwatch
impl UnwindSafe for Stopwatch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more