aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-01-25 10:59:11 +0000
committerAleksey Kladov <[email protected]>2020-01-25 10:59:11 +0000
commit6577a7622d5053f35c16eed47516265c98e5212e (patch)
tree4bf167645d4b7f098140612086424f6a0de69719 /crates
parentf44aee27d31ca331fee8993152c42875b3364711 (diff)
Add print_time helper
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_prof/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
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 {
106 }) 106 })
107} 107}
108 108
109pub 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
109pub struct Profiler { 124pub struct Profiler {
110 desc: Option<String>, 125 desc: Option<String>,
111} 126}