Commit | Line | Data |
---|---|---|
af18b07f TW |
1 | use std::time::Instant; |
2 | ||
3 | pub struct ScopeTimer { | |
4 | #[allow(dead_code)] | |
5 | start: Instant, | |
6 | #[allow(dead_code)] | |
7 | name: &'static str, | |
8 | } | |
9 | ||
10 | impl ScopeTimer { | |
11 | pub fn new(name: &'static str) -> Self { | |
0c56b1f7 | 12 | ScopeTimer { start: Instant::now(), name } |
af18b07f TW |
13 | } |
14 | } | |
15 | ||
16 | #[cfg(debug_assertions)] | |
17 | impl Drop for ScopeTimer { | |
18 | fn drop(&mut self) { | |
19 | println!("{} took {:?}", self.name, self.start.elapsed()); | |
20 | } | |
21 | } | |
22 | ||
23 | #[macro_export] | |
24 | macro_rules! time_scope { | |
25 | () => { | |
5433a77f | 26 | use util::ScopeTimer; |
af18b07f TW |
27 | let _magical_scope_timer_ = ScopeTimer::new("scope"); |
28 | }; | |
29 | ( $name:expr ) => { | |
5433a77f | 30 | use util::ScopeTimer; |
af18b07f TW |
31 | let _magical_scope_timer_ = ScopeTimer::new($name); |
32 | }; | |
33 | } |