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 common::ScopeTimer; let _magical_scope_timer_ = ScopeTimer::new("scope"); }; ( $name:expr ) => { use common::ScopeTimer; let _magical_scope_timer_ = ScopeTimer::new($name); }; }