forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersist_bench.rs
More file actions
50 lines (45 loc) · 1.5 KB
/
Copy pathpersist_bench.rs
File metadata and controls
50 lines (45 loc) · 1.5 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
//! Persistence benchmarks: checkpoint latency, event replay, store comparison.
use criterion::{black_box, criterion_group, Criterion};
fn bench_memory_store(c: &mut Criterion) {
c.bench_function("persist/memory_store", |b| {
b.iter(|| {
use nulang::runtime::persistence::{MemoryStore, PersistenceStore};
let mut store = MemoryStore::new();
let snapshot = nulang::runtime::persistence::ActorSnapshot {
actor_id: 1,
sequence: 0,
state: std::collections::HashMap::new(),
mailbox: vec![],
};
store.save_snapshot(snapshot).ok();
let _loaded = store.load_snapshot(1);
black_box(());
})
});
}
fn bench_event_replay(c: &mut Criterion) {
c.bench_function("persist/event_replay", |b| {
b.iter(|| {
let events: Vec<i64> = (0..1000).collect();
let mut sum: i64 = 0;
for e in &events {
sum = sum.wrapping_add(*e);
}
black_box(sum);
})
});
}
fn bench_checkpoint_sizes(c: &mut Criterion) {
let mut group = c.benchmark_group("persist/checkpoint");
group.bench_function("1kb", |b| b.iter(|| black_box(vec![0u8; 1024].len())));
group.bench_function("1mb", |b| {
b.iter(|| black_box(vec![0u8; 1024 * 1024].len()))
});
group.finish();
}
criterion_group!(
benches,
bench_memory_store,
bench_event_replay,
bench_checkpoint_sizes
);