X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcommon%2Ftime.rs;fp=src%2Fcommon%2Ftime.rs;h=0468d5d22871b544c372913033af4fc74b1126c7;hb=af18b07f3ff382c0bb122d0e0b235cd7991a2597;hp=0000000000000000000000000000000000000000;hpb=eb253fcc25b0af3ec7b804ea8e1b73426564883b;p=kaka%2Frust-sdl-test.git diff --git a/src/common/time.rs b/src/common/time.rs new file mode 100644 index 0000000..0468d5d --- /dev/null +++ b/src/common/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: 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 common::ScopeTimer; + let _magical_scope_timer_ = ScopeTimer::new("scope"); + }; + ( $name:expr ) => { + use common::ScopeTimer; + let _magical_scope_timer_ = ScopeTimer::new($name); + }; +}