Files
hyperfine/src/hyperfine/timer/wallclocktimer.rs
T

30 lines
642 B
Rust
Raw Normal View History

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,
}
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();
duration.as_secs() as f64 + (duration.subsec_nanos() as f64) * 1e-9
}
}