diff options
author | Aleksey Kladov <[email protected]> | 2020-04-10 19:46:42 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-10 19:46:42 +0100 |
commit | 1b68c72fe93424213db895a4066eafb99dfdeac9 (patch) | |
tree | 5530ff52ddd3fde6725844a2107aaa566ea45c96 | |
parent | 72a0db8dc46c63409a93745d04758049515abaf0 (diff) |
Move timeit to stdx
-rw-r--r-- | crates/ra_prof/src/lib.rs | 15 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 16 |
2 files changed, 15 insertions, 16 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 00ea3a9b0..2d4f68f5e 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -113,21 +113,6 @@ pub fn profile(label: Label) -> Profiler { | |||
113 | }) | 113 | }) |
114 | } | 114 | } |
115 | 115 | ||
116 | pub fn print_time(label: Label) -> impl Drop { | ||
117 | struct Guard { | ||
118 | label: Label, | ||
119 | start: Instant, | ||
120 | } | ||
121 | |||
122 | impl Drop for Guard { | ||
123 | fn drop(&mut self) { | ||
124 | eprintln!("{}: {:?}", self.label, self.start.elapsed()) | ||
125 | } | ||
126 | } | ||
127 | |||
128 | Guard { label, start: Instant::now() } | ||
129 | } | ||
130 | |||
131 | pub struct Profiler { | 116 | pub struct Profiler { |
132 | label: Option<Label>, | 117 | label: Option<Label>, |
133 | detail: Option<String>, | 118 | detail: Option<String>, |
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 401a568bd..01cdf452c 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Missing batteries for standard libraries. | 1 | //! Missing batteries for standard libraries. |
2 | 2 | ||
3 | use std::{cell::Cell, fmt}; | 3 | use std::{cell::Cell, fmt, time::Instant}; |
4 | 4 | ||
5 | #[inline(always)] | 5 | #[inline(always)] |
6 | pub fn is_ci() -> bool { | 6 | pub fn is_ci() -> bool { |
@@ -88,3 +88,17 @@ where | |||
88 | Ok(()) | 88 | Ok(()) |
89 | } | 89 | } |
90 | } | 90 | } |
91 | pub fn timeit(label: &'static str) -> impl Drop { | ||
92 | struct Guard { | ||
93 | label: &'static str, | ||
94 | start: Instant, | ||
95 | } | ||
96 | |||
97 | impl Drop for Guard { | ||
98 | fn drop(&mut self) { | ||
99 | eprintln!("{}: {:?}", self.label, self.start.elapsed()) | ||
100 | } | ||
101 | } | ||
102 | |||
103 | Guard { label, start: Instant::now() } | ||
104 | } | ||