mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Add print_time helper
This commit is contained in:
parent
f44aee27d3
commit
6577a7622d
1 changed files with 15 additions and 0 deletions
|
@ -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>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue