forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.rs
81 lines (69 loc) · 2.21 KB
/
run.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
use criterion::{criterion_group, criterion_main, Criterion};
use wasmer::*;
static BENCHMARKS_ARTIFACTS_BASE_URL: &str = "https://pub-083d1a0568d446d1aa5b2e07bd16983b.r2.dev";
fn get_engine() -> Engine {
#[cfg(feature = "llvm")]
return LLVM::new().into();
#[cfg(feature = "singlepass")]
return Singlepass::new().into();
#[cfg(feature = "cranelift")]
return Cranelift::new().into();
#[cfg(not(any(feature = "cranelift", feature = "llvm", feature = "singlepass")))]
return Default::default();
}
pub fn run_fn(c: &mut Criterion, module: &[u8], name: &str, input: i64) {
c.bench_function(name, |b| {
let engine = get_engine();
let mut store = Store::new(engine);
let module = Module::new(&store, module).unwrap();
let import_object = imports! {};
let instance = Instance::new(&mut store, &module, &import_object).unwrap();
let func = instance
.exports
.get_typed_function::<i64, i64>(&store, "run")
.unwrap();
b.iter(|| {
func.call(&mut store, input);
})
});
}
pub fn download_and_run(c: &mut Criterion) {
let name = if cfg!(feature = "cranelift") {
"cranelift"
} else if cfg!(feature = "llvm") {
"llvm"
} else if cfg!(feature = "singlepass") {
"singlepass"
} else if cfg!(feature = "v8") {
"v8"
} else if cfg!(feature = "wamr") {
"wamr"
} else if cfg!(feature = "wasmi") {
"wasmi"
} else {
panic!("Unrecognized backend!")
};
let modules = [
("counter", 5_000_000),
("primes", 1_000),
("fib_rec", 40),
("fib_iter", 2_000_000),
("bulk_ops", 5_000),
("matmul", 200),
("argon2", 1),
];
for (module, arg) in modules {
let bytes =
reqwest::blocking::get(format!("{BENCHMARKS_ARTIFACTS_BASE_URL}/{module}.wasm"))
.unwrap()
.bytes()
.unwrap();
run_fn(c, bytes.as_ref(), &format!("exec/{name}/{module}"), arg);
}
}
criterion_group!(
name = run_benches;
config = Criterion::default().sample_size(60);
targets = download_and_run
);
criterion_main!(run_benches);