2018-02-07 19:03:52 -05:00
|
|
|
use std::process::Child;
|
2018-02-02 17:28:52 +01:00
|
|
|
use std::time::Instant;
|
|
|
|
|
|
2019-05-07 11:55:38 +02:00
|
|
|
use crate::hyperfine::timer::{TimerStart, TimerStop};
|
|
|
|
|
use crate::hyperfine::units::Second;
|
2018-02-02 17:28:52 +01:00
|
|
|
|
|
|
|
|
pub struct WallClockTimer {
|
|
|
|
|
start: Instant,
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 19:03:52 -05:00
|
|
|
impl TimerStart for WallClockTimer {
|
2018-02-02 17:28:52 +01:00
|
|
|
fn start() -> WallClockTimer {
|
|
|
|
|
WallClockTimer {
|
|
|
|
|
start: Instant::now(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 19:03:52 -05:00
|
|
|
fn start_for_process(_: &Child) -> Self {
|
|
|
|
|
Self::start()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TimerStop for WallClockTimer {
|
|
|
|
|
type Result = Second;
|
|
|
|
|
|
2018-02-02 17:28:52 +01:00
|
|
|
fn stop(&self) -> Second {
|
|
|
|
|
let duration = self.start.elapsed();
|
|
|
|
|
duration.as_secs() as f64 + (duration.subsec_nanos() as f64) * 1e-9
|
|
|
|
|
}
|
|
|
|
|
}
|