Renamed common to util
[kaka/rust-sdl-test.git] / src / util / time.rs
CommitLineData
af18b07f
TW
1use std::time::Instant;
2
3pub struct ScopeTimer {
4 #[allow(dead_code)]
5 start: Instant,
6 #[allow(dead_code)]
7 name: &'static str,
8}
9
10impl 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)]
17impl Drop for ScopeTimer {
18 fn drop(&mut self) {
19 println!("{} took {:?}", self.name, self.start.elapsed());
20 }
21}
22
23#[macro_export]
24macro_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}