extern crate time;
#[derive(Clone, Copy)]
pub struct Stopwatch {
start_time_ns: u64,
}
impl Stopwatch {
pub fn start_new() -> Stopwatch {
Stopwatch {
start_time_ns: time::precise_time_ns(),
}
}
pub fn restart(&mut self) {
*self = Stopwatch::start_new();
}
pub fn s(&self) -> f32 {
(time::precise_time_ns() - self.start_time_ns) as f32 / 1000000000f32
}
pub fn ms(&self) -> f32 {
(time::precise_time_ns() - self.start_time_ns) as f32 / 1000000f32
}
pub fn us(&self) -> f32 {
(time::precise_time_ns() - self.start_time_ns) as f32 / 1000f32
}
pub fn ns(&self) -> f32 {
(time::precise_time_ns() - self.start_time_ns) as f32
}
}