From 6577a7622d5053f35c16eed47516265c98e5212e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Jan 2020 11:59:11 +0100 Subject: Add print_time helper --- crates/ra_prof/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ra_prof/src') diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index da541005a..c7973ddf4 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -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 { desc: Option, } -- cgit v1.2.3