-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprof.rs
More file actions
38 lines (33 loc) · 827 Bytes
/
Copy pathprof.rs
File metadata and controls
38 lines (33 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::time::Instant;
pub struct ScopeTimer {
label: &'static str,
start: Instant,
}
impl ScopeTimer {
pub fn new(label: &'static str) -> Self {
Self { label, start: Instant::now() }
}
pub fn elapsed(&self) -> std::time::Duration {
self.start.elapsed()
}
}
impl Drop for ScopeTimer {
fn drop(&mut self) {
println!("{} took {:?}", self.label, self.start.elapsed());
}
}
#[macro_export]
macro_rules! profile_scope {
($label:expr) => {
let _profile_scope_timer = $crate::prof::ScopeTimer::new($label);
};
}
#[macro_export]
macro_rules! profile_call {
($label:expr, $expr:expr) => {{
let __start = std::time::Instant::now();
let __ret = { $expr };
println!("{} took {:?}", $label, __start.elapsed());
__ret
}};
}