forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc_bench.rs
More file actions
63 lines (59 loc) · 1.93 KB
/
Copy pathgc_bench.rs
File metadata and controls
63 lines (59 loc) · 1.93 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
//! GC benchmarks: ORCA throughput, cycle detection.
use criterion::{black_box, criterion_group, Criterion};
use nulang::runtime::Runtime;
use nulang::types::ExitReason;
use nulang::vm::Value;
fn bench_orca_throughput(c: &mut Criterion) {
c.bench_function("gc/orca_throughput", |b| {
b.iter(|| {
let mut rt = Runtime::new();
let mut actors = Vec::new();
for _ in 0..20 {
let a = rt.spawn_actor(Box::new(|| vec![]));
actors.push(a);
}
let msg = Value::int(42);
for i in 0..20 {
for j in 0..20 {
if i != j {
rt.send_message(actors[i], "handle", &[msg]);
}
}
}
for _ in 0..200 {
rt.run_scheduler();
rt.process_gc_ops();
}
for a in &actors {
rt.exit_actor(*a, ExitReason::Normal);
}
for _ in 0..100 {
rt.run_scheduler();
rt.process_gc_ops();
}
black_box(());
})
});
}
fn bench_cycle_detection(c: &mut Criterion) {
c.bench_function("gc/cycle_detection", |b| {
b.iter(|| {
let mut rt = Runtime::new();
let a = rt.spawn_actor(Box::new(|| vec![]));
let b = rt.spawn_actor(Box::new(|| vec![]));
let c = rt.spawn_actor(Box::new(|| vec![]));
rt.monitor(a, b);
rt.monitor(b, c);
rt.monitor(c, a);
rt.exit_actor(a, ExitReason::Normal);
rt.exit_actor(b, ExitReason::Normal);
rt.exit_actor(c, ExitReason::Normal);
for _ in 0..200 {
rt.run_scheduler();
rt.process_gc_ops();
}
black_box(());
})
});
}
criterion_group!(benches, bench_orca_throughput, bench_cycle_detection);