Repository navigation
Expand file tree
/
Copy pathdoomgram.rs
More file actions
75 lines (58 loc) · 1.68 KB
/
Copy pathdoomgram.rs
File metadata and controls
75 lines (58 loc) · 1.68 KB
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
// examples/doomgram.rs : example program illustrating use of `DoomGram`
use diagnosticism::{
doom_scope,
DoomGram,
};
use rand::{
rngs::StdRng,
Rng,
SeedableRng,
};
use std::{
thread,
time::{
Duration,
Instant,
},
};
fn main() {
let mut rng = <StdRng as SeedableRng>::seed_from_u64(123456789);
let mut dg = DoomGram::default();
// do a warmup loop first
for w in 0..2 {
for i in 0..20000 {
let mut v = rng.next_u32() % 1000000;
if 0 == i % 10 {
if 0 != i {
v = v % i;
}
}
doom_scope(&mut dg, || {
if 0 != i % 2000 {
thread::sleep(Duration::from_nanos(v as u64));
} else {
// no wait, so should be very low ns
thread::sleep(Duration::from_secs(0));
}
});
}
// output results on second run through
if 1 == w {
let before = Instant::now();
let strip = dg.to_strip();
let after = Instant::now();
eprintln!("`#to_strip()` : {strip} (in {:?})", after - before);
let before = Instant::now();
let mmm = dg.to_mmm();
let after = Instant::now();
eprintln!("`#to_mmm()` : {mmm} (in {:?})", after - before);
let before = Instant::now();
let nmmm = dg.to_nmmm();
let after = Instant::now();
eprintln!("`#to_nmmm()` : {nmmm} (in {:?})", after - before);
eprintln!();
eprintln!("dg={dg:#?}");
}
dg.clear();
}
}