Files
hyperfine/src/timer/wallclocktimer.rs
T

30 lines
622 B
Rust
Raw Normal View History

use std::process::Child;
2018-02-02 17:28:52 +01:00
use std::time::Instant;
2021-08-24 21:24:34 +02:00
use crate::timer::{TimerStart, TimerStop};
use crate::units::Second;
2018-02-02 17:28:52 +01:00
pub struct WallClockTimer {
start: Instant,
}
impl TimerStart for WallClockTimer {
2018-02-02 17:28:52 +01:00
fn start() -> WallClockTimer {
WallClockTimer {
start: Instant::now(),
}
}
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();
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
}
}