2018-02-02 17:28:52 +01:00
|
|
|
use std::time::Instant;
|
|
|
|
|
|
2022-02-06 20:01:41 +01:00
|
|
|
use crate::util::units::Second;
|
2018-02-02 17:28:52 +01:00
|
|
|
|
|
|
|
|
pub struct WallClockTimer {
|
|
|
|
|
start: Instant,
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-22 10:29:58 +01:00
|
|
|
impl WallClockTimer {
|
|
|
|
|
pub fn start() -> WallClockTimer {
|
2018-02-02 17:28:52 +01:00
|
|
|
WallClockTimer {
|
|
|
|
|
start: Instant::now(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-22 10:29:58 +01:00
|
|
|
pub fn stop(&self) -> Second {
|
2018-02-02 17:28:52 +01:00
|
|
|
let duration = self.start.elapsed();
|
2019-07-13 10:15:22 +02:00
|
|
|
duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) * 1e-9
|
2018-02-02 17:28:52 +01:00
|
|
|
}
|
|
|
|
|
}
|