X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Futil%2Ftime.rs;fp=src%2Futil%2Ftime.rs;h=b533bb6f9265272b80c06b1cd95024880588a697;hb=5433a77fa53c337c07577dc02d769616945d58ea;hp=0000000000000000000000000000000000000000;hpb=953b4c960649b82f4e186c2a9afee5367270f0fc;p=kaka%2Frust-sdl-test.git diff --git a/src/util/time.rs b/src/util/time.rs new file mode 100644 index 0000000..b533bb6 --- /dev/null +++ b/src/util/time.rs @@ -0,0 +1,33 @@ +use std::time::Instant; + +pub struct ScopeTimer { + #[allow(dead_code)] + start: Instant, + #[allow(dead_code)] + name: &'static str, +} + +impl ScopeTimer { + pub fn new(name: &'static str) -> Self { + ScopeTimer { start: Instant::now(), name } + } +} + +#[cfg(debug_assertions)] +impl Drop for ScopeTimer { + fn drop(&mut self) { + println!("{} took {:?}", self.name, self.start.elapsed()); + } +} + +#[macro_export] +macro_rules! time_scope { + () => { + use util::ScopeTimer; + let _magical_scope_timer_ = ScopeTimer::new("scope"); + }; + ( $name:expr ) => { + use util::ScopeTimer; + let _magical_scope_timer_ = ScopeTimer::new($name); + }; +}