-
Notifications
You must be signed in to change notification settings - Fork 135
/
benchmark.rs
59 lines (53 loc) · 1.73 KB
/
benchmark.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
use std::{collections::HashMap, sync::Arc};
use criterion::{criterion_group, criterion_main, Criterion};
// TODO: Re-export this under lunatic_runtime
use lunatic_process::{
env::LunaticEnvironment,
runtimes::wasmtime::{default_config, WasmtimeRuntime},
};
use lunatic_runtime::{state::DefaultProcessState, DefaultProcessConfig};
use tokio::sync::RwLock;
fn criterion_benchmark(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
let config = Arc::new(DefaultProcessConfig::default());
let wasmtime_config = default_config();
let runtime = WasmtimeRuntime::new(&wasmtime_config).unwrap();
let raw_module = wat::parse_file("./wat/hello.wat").unwrap();
let module = Arc::new(
runtime
.compile_module::<DefaultProcessState>(raw_module.into())
.unwrap(),
);
let env = Arc::new(LunaticEnvironment::new(0));
c.bench_function("spawn process", |b| {
b.to_async(&rt).iter(|| async {
let registry = Arc::new(RwLock::new(HashMap::new()));
let state = DefaultProcessState::new(
env.clone(),
None,
runtime.clone(),
module.clone(),
config.clone(),
registry,
)
.unwrap();
lunatic_process::wasm::spawn_wasm(
env.clone(),
runtime.clone(),
&module,
state,
"hello",
Vec::new(),
None,
)
.await
.unwrap()
.0
.await
.unwrap()
.ok();
});
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);