forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdist_bench.rs
More file actions
48 lines (44 loc) · 1.59 KB
/
Copy pathdist_bench.rs
File metadata and controls
48 lines (44 loc) · 1.59 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
//! Distribution benchmarks: CRDT delta sync, gossip convergence.
use criterion::{black_box, criterion_group, Criterion};
fn bench_dist_crdt_delta_sync(c: &mut Criterion) {
c.bench_function("dist/crdt_delta_sync", |b| {
b.iter(|| {
use nulang::runtime::crdt::GCounter;
let mut counter = GCounter::new(1);
counter.increment();
counter.increment();
let base = GCounter::new(2);
let delta = counter.delta_since(&base);
black_box(delta);
})
});
}
fn bench_dist_gossip_convergence(c: &mut Criterion) {
c.bench_function("dist/gossip_convergence", |b| {
b.iter(|| {
use nulang::runtime::cluster::{ClusterState, NodeGossip, NodeId, NodeStatus};
use std::net::SocketAddr;
let addr: SocketAddr = "127.0.0.1:9001".parse().unwrap();
let node_id = NodeId::new(&addr);
let mut cs = ClusterState::new(node_id, addr);
let gossip: Vec<NodeGossip> = (2..=5)
.map(|n| {
let a: SocketAddr = format!("127.0.0.1:900{}", n).parse().unwrap();
NodeGossip {
node_id: NodeId::new(&a),
address: a.to_string(),
status: NodeStatus::Healthy,
incarnation: 1,
}
})
.collect();
cs.merge_membership(gossip);
black_box(cs);
})
});
}
criterion_group!(
benches,
bench_dist_crdt_delta_sync,
bench_dist_gossip_convergence
);