-
Notifications
You must be signed in to change notification settings - Fork 9
/
z_run.rs
50 lines (48 loc) · 1.33 KB
/
z_run.rs
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
use std::time::Duration;
use std::time::Instant;
#[allow(unused_macros)]
macro_rules! run {
($name:expr, $f:expr) => {
let mut sum_elapsed = Duration::new(0, 0);
let mut count = 0u32;
loop {
let now = Instant::now();
$f;
let elapsed = now.elapsed();
sum_elapsed += elapsed;
count += 1;
if sum_elapsed >= Duration::from_millis(MIN_BENCH_TIME) {
break;
}
}
println!(
"{},{},{}",
$name,
(sum_elapsed / count).as_nanos(),
((count as f64 * MESSAGES as f64) / sum_elapsed.as_secs_f64()).round()
);
};
}
#[allow(unused_macros)]
macro_rules! run_async {
($name:expr, $f:expr) => {
let mut sum_elapsed = Duration::new(0, 0);
let mut count = 0u32;
loop {
let now = Instant::now();
$f.await;
let elapsed = now.elapsed();
sum_elapsed += elapsed;
count += 1;
if sum_elapsed >= Duration::from_millis(MIN_BENCH_TIME) {
break;
}
}
println!(
"{},{},{}",
$name,
(sum_elapsed / count).as_nanos(),
((count as f64 * MESSAGES as f64) / sum_elapsed.as_secs_f64()).round()
);
};
}