use console::style;
use std::time::Instant;
#[derive(Debug)]
pub struct PrintTime {
pub location: String,
pub start: Instant,
}
impl PrintTime {
pub fn new(location: impl Into<String>) -> Self {
PrintTime {
location: location.into(),
start: Instant::now(),
}
}
}
impl Drop for PrintTime {
fn drop(&mut self) {
let PrintTime { location, start } = self;
eprintln!(
"[TIMINGS]: {}: {:.6} seconds elapsed.",
style(location).bold(),
(Instant::now() - *start).as_secs_f64()
);
}
}
macro_rules! print_scope_time {
() => {
$crate::benchmarking::PrintTime::new(format!(
"{}:{}:{}",
module_path!(),
line!(),
column!()
))
};
($msg:expr) => {
$crate::benchmarking::PrintTime::new(format!(
"{}:{}:{} ({})",
module_path!(),
line!(),
column!(),
$msg
))
};
}
pub(super) use print_scope_time;