Add print_time helper

This commit is contained in:
Aleksey Kladov 2020-01-25 11:59:11 +01:00
parent f44aee27d3
commit 6577a7622d

View file

@ -106,6 +106,21 @@ pub fn profile(desc: &str) -> Profiler {
}) })
} }
pub fn print_time(desc: &str) -> impl Drop + '_ {
struct Guard<'a> {
desc: &'a str,
start: Instant,
}
impl Drop for Guard<'_> {
fn drop(&mut self) {
eprintln!("{}: {:?}", self.desc, self.start.elapsed())
}
}
Guard { desc, start: Instant::now() }
}
pub struct Profiler { pub struct Profiler {
desc: Option<String>, desc: Option<String>,
} }