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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#[cfg(feature = "verbose")]
use std;
#[cfg(feature = "verbose")]
pub static mut STACK: Option<Vec<(String, std::time::Instant, std::time::Instant)>> = None;
#[cfg(feature = "verbose")]
macro_rules! start_talking_about_time {
($category:expr) => (
use std;
use verbose;
unsafe {
let stack = verbose::STACK.get_or_insert_with(|| Vec::new());
let len = stack.len();
let now = std::time::Instant::now();
let category = $category;
stack.push((String::from(category), now.clone(), now.clone()));
eprintln!("{}starting {}", " ".repeat(len), category);
}
)
}
#[cfg(feature = "verbose")]
macro_rules! talk_about_time {
($what:expr) => (
unsafe {
let stack = verbose::STACK.get_or_insert_with(|| Vec::new());
let len = stack.len();
let last = stack.last_mut().unwrap();
let elapsed = last.1.elapsed();
eprintln!(
"{}{}: {} took {}.{:09}s",
" ".repeat(len),
last.0,
$what,
elapsed.as_secs(),
elapsed.subsec_nanos()
);
last.1 = std::time::Instant::now();
}
)
}
#[cfg(feature = "verbose")]
macro_rules! stop_talking_about_time {
() => (
unsafe {
let stack = verbose::STACK.get_or_insert_with(|| Vec::new());
let last = stack.pop().unwrap();
let elapsed = last.2.elapsed();
let len = stack.len();
eprintln!(
"{}ending {} (total {}.{:09}s)",
" ".repeat(len),
last.0,
elapsed.as_secs(),
elapsed.subsec_nanos()
);
}
)
}
#[cfg(not(feature = "verbose"))]
macro_rules! start_talking_about_time {
($e:expr) => ()
}
#[cfg(not(feature = "verbose"))]
macro_rules! talk_about_time {
($e:expr) => ()
}
#[cfg(not(feature = "verbose"))]
macro_rules! stop_talking_about_time {
() => ()
}
|