2023-02-04 21:41:32 +01:00
|
|
|
use std::time::{self, Duration};
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
|
|
pub struct Timer {
|
|
|
|
title: &'static str,
|
|
|
|
time: Instant,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Timer {
|
|
|
|
fn drop(&mut self) {
|
2023-02-11 05:42:02 +01:00
|
|
|
let micros = self.time.elapsed().as_micros();
|
|
|
|
let millis = self.time.elapsed().as_millis();
|
|
|
|
|
|
|
|
if micros < 10000 {
|
|
|
|
println!("{} ended in {}us", self.title, self.time.elapsed().as_micros());
|
|
|
|
} else {
|
|
|
|
println!("{} ended in {}ms", self.title, self.time.elapsed().as_millis());
|
|
|
|
}
|
|
|
|
|
2023-02-04 21:41:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Timer {
|
|
|
|
pub fn new(title: &'static str) -> Timer {
|
|
|
|
let start = Instant::now();
|
|
|
|
Timer {
|
|
|
|
title,
|
|
|
|
time: start,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|