-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
heap.rs
121 lines (108 loc) · 3.94 KB
/
heap.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Run with `RUSTFLAGS='-Ctarget-cpu=native' cargo bench` to enable all
// optimizations such as SSE
#[macro_use]
extern crate criterion;
use std::time::Duration;
use criterion::{Criterion, Throughput};
use rand::distributions::{Distribution, Uniform};
use violin::{heap::VecD, Config, Coord, Node, Vector};
const SAMPLES: u64 = 100;
const NODES: u64 = 10_000;
// Pre-compute "random" rtts
fn gen_duration_rtts() -> Vec<Duration> {
gen_rtts()
.iter()
.map(|&rtt| Duration::from_secs_f64(rtt))
.collect()
}
fn gen_rtts() -> Vec<f64> {
let mut rng = rand::thread_rng();
let die = Uniform::from(1.0e-5..5.0);
let rtts: Vec<f64> = vec![0.0f64; (NODES * SAMPLES) as usize]
.iter_mut()
.map(|_rtt| die.sample(&mut rng))
.collect();
rtts
}
fn do_node_updates<T: Vector + Clone>(
nodes: &mut [Node<T>],
peers: &mut [Node<T>],
rtts: &[Duration],
) {
let mut i: usize = 0;
while i < SAMPLES as usize {
for (j, (n, p)) in nodes.iter_mut().zip(peers.iter()).enumerate() {
n.update(rtts[i + j], p.coordinate());
}
i += 1;
}
}
fn do_coord_updates<T: Vector + Clone>(
nodes: &mut [Coord<T>],
peers: &mut [Coord<T>],
cfg: &Config,
rtts: &[f64],
) {
let mut i: usize = 0;
while i < SAMPLES as usize {
for (j, (n, p)) in nodes.iter_mut().zip(peers.iter()).enumerate() {
n.update(rtts[i + j], p, cfg);
}
i += 1;
}
}
pub fn benchmarks(c: &mut Criterion) {
let mut group = c.benchmark_group("violin::Node");
group.throughput(Throughput::Elements(SAMPLES * NODES));
group.bench_function("heap 8D (0 adjustment window)", |b| {
// Create Coords
let mut nodes = vec![Node::<VecD<8>>::default(); NODES as usize];
let mut peers = vec![Node::<VecD<8>>::default(); NODES as usize];
let rtts = gen_duration_rtts();
b.iter(|| do_node_updates(&mut nodes, &mut peers, &rtts))
});
group.bench_function("heap 4D (0 adjustment window)", |b| {
// Create Coords
let mut nodes = vec![Node::<VecD<4>>::default(); NODES as usize];
let mut peers = vec![Node::<VecD<4>>::default(); NODES as usize];
let rtts = gen_duration_rtts();
b.iter(|| do_node_updates(&mut nodes, &mut peers, &rtts))
});
group.bench_function("heap 2D (0 adjustment window)", |b| {
// Create Coords
let mut nodes = vec![Node::<VecD<2>>::default(); NODES as usize];
let mut peers = vec![Node::<VecD<2>>::default(); NODES as usize];
let rtts = gen_duration_rtts();
b.iter(|| do_node_updates(&mut nodes, &mut peers, &rtts))
});
group.finish();
let mut group = c.benchmark_group("violin::Coord");
group.throughput(Throughput::Elements(SAMPLES * NODES));
group.bench_function("heap 8D", |b| {
// Create Coords
let mut nodes = vec![Coord::<VecD<8>>::default(); NODES as usize];
let mut peers = vec![Coord::<VecD<8>>::default(); NODES as usize];
let rtts = gen_rtts();
let cfg = Config::default();
b.iter(|| do_coord_updates(&mut nodes, &mut peers, &cfg, &rtts))
});
group.bench_function("heap 4D", |b| {
// Create Coords
let mut nodes = vec![Coord::<VecD<4>>::default(); NODES as usize];
let mut peers = vec![Coord::<VecD<4>>::default(); NODES as usize];
let rtts = gen_rtts();
let cfg = Config::default();
b.iter(|| do_coord_updates(&mut nodes, &mut peers, &cfg, &rtts))
});
group.bench_function("heap 2D", |b| {
// Create Coords
let mut nodes = vec![Coord::<VecD<2>>::default(); NODES as usize];
let mut peers = vec![Coord::<VecD<2>>::default(); NODES as usize];
let rtts = gen_rtts();
let cfg = Config::default();
b.iter(|| do_coord_updates(&mut nodes, &mut peers, &cfg, &rtts))
});
group.finish();
}
criterion_group!(benches, benchmarks);
criterion_main!(benches);