-
Notifications
You must be signed in to change notification settings - Fork 1
/
spawner.rs
77 lines (60 loc) · 1.96 KB
/
spawner.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
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
77
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::{mpsc, Arc};
use itertools::iproduct;
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use tokiobench::params;
use tokiobench::rt;
use tokiobench::spawner as sp;
fn bench(bench_fn: sp::BenchFn, name: &str, c: &mut Criterion) {
let (tx, rx) = mpsc::sync_channel(1000);
let rem: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
let mut group = c.benchmark_group(name);
for (nspawn, nworkers) in iproduct!(params::NS_SPAWN_LOCAL, params::NS_WORKERS) {
let rt = rt::new(nworkers);
group.throughput(Throughput::Elements(nspawn as u64));
group.bench_with_input(
format!("nspawn({nspawn})/nwork({nworkers})"),
&nspawn,
|b, &nspawn| {
b.iter(|| {
let tx = tx.clone();
let rem = rem.clone();
rem.store(nspawn, Relaxed);
rt.block_on(async {
bench_fn(nspawn, tx, rem);
rx.recv().unwrap();
});
});
},
);
}
}
fn spawn_current(c: &mut Criterion) {
bench(sp::spawn_current, "spawn_current", c)
}
fn spawn_local(c: &mut Criterion) {
bench(sp::spawn_local, "spawn_local", c);
}
fn spawn_local_float_max(c: &mut Criterion) {
bench(sp::spawn_local, "spawn_local_float_max", c);
}
fn spawn_local_int_max(c: &mut Criterion) {
bench(sp::spawn_local, "spawn_local_int_max", c);
}
fn spawn_current_float_max(c: &mut Criterion) {
bench(sp::spawn_current, "spawn_current_float_max", c)
}
fn spawn_current_int_max(c: &mut Criterion) {
bench(sp::spawn_current, "spawn_current_int_max", c)
}
criterion_group!(
benches,
spawn_current,
spawn_local,
spawn_local_float_max,
spawn_local_int_max,
spawn_current_float_max,
spawn_current_int_max,
);
criterion_main!(benches);