use std::fmt::Display;
use std::fmt::Formatter;
use std::time::Duration;
use std::time::Instant;
#[must_use]
pub struct Stopwatch {
start_timestamp: Instant,
}
impl Stopwatch {
pub fn start() -> Self {
Self { start_timestamp: Instant::now() }
}
#[must_use]
pub fn elapsed(&self) -> Duration {
self.start_timestamp.elapsed()
}
}
impl Display for Stopwatch {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let dur = self.elapsed();
let millis: f32 = dur.as_secs_f32() * 1000.0;
write!(f, "{millis:.2} ms")
}
}