Skip to content

Commit 6577a76

Browse files
committed
Add print_time helper
1 parent f44aee2 commit 6577a76

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/ra_prof/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ pub fn profile(desc: &str) -> Profiler {
106106
})
107107
}
108108

109+
pub fn print_time(desc: &str) -> impl Drop + '_ {
110+
struct Guard<'a> {
111+
desc: &'a str,
112+
start: Instant,
113+
}
114+
115+
impl Drop for Guard<'_> {
116+
fn drop(&mut self) {
117+
eprintln!("{}: {:?}", self.desc, self.start.elapsed())
118+
}
119+
}
120+
121+
Guard { desc, start: Instant::now() }
122+
}
123+
109124
pub struct Profiler {
110125
desc: Option<String>,
111126
}

0 commit comments

Comments
 (0)