Skip to content

Commit f58a75f

Browse files
committed
Updates.
1 parent 2bf0bcf commit f58a75f

1 file changed

Lines changed: 45 additions & 14 deletions

File tree

benches/memory_copy.rs

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use std::time::Duration;
33

4-
const MEM_SIZE: [usize; 11] = [
4+
/// Lengths used for benchmarking.
5+
const LENGTHS: [usize; 30] = [
56
1,
7+
2,
8+
5,
9+
10,
10+
20,
11+
50,
612
100,
13+
200,
14+
500,
715
1_000,
16+
2_000,
17+
5_000,
818
10_000,
19+
20_000,
20+
50_000,
921
100_000,
22+
200_000,
23+
500_000,
1024
1_000_000,
25+
2_000_000,
26+
5_000_000,
1127
10_000_000,
28+
20_000_000,
29+
50_000_000,
1230
100_000_000,
31+
200_000_000,
32+
500_000_000,
1333
1_000_000_000,
1434
2_000_000_000,
1535
4_000_000_000,
@@ -27,19 +47,6 @@ const TEMPLATE: &str = r#"
2747
)
2848
"#;
2949

30-
fn _0001(c: &mut Criterion) {
31-
let mut group = c.benchmark_group("memory-copy");
32-
for mem_size in MEM_SIZE {
33-
let wasm_bytes = wat::parse_str(wat_source(mem_size)).unwrap();
34-
let compiler = wasmer::sys::Singlepass::default();
35-
let mut store = wasmer::Store::new(compiler);
36-
let module = wasmer::Module::from_binary(&store, &wasm_bytes).unwrap();
37-
let instance = wasmer::Instance::new(&mut store, &module, &wasmer::imports! {}).unwrap();
38-
let fun = instance.exports.get_typed_function::<(), ()>(&store, "fun").unwrap();
39-
group.bench_with_input(format!("size = {mem_size}"), &mem_size, |b, &_mem_size| b.iter(|| fun.call(&mut store).unwrap()));
40-
}
41-
}
42-
4350
fn wat_source(length: usize) -> String {
4451
TEMPLATE.replace("<LENGTH>", &length.to_string())
4552
}
@@ -52,5 +59,29 @@ fn make_config() -> Criterion {
5259
.configure_from_args()
5360
}
5461

62+
fn _0001(c: &mut Criterion) {
63+
let mut group = c.benchmark_group("memory-copy");
64+
for length in LENGTHS {
65+
let wasm_bytes = wat::parse_str(wat_source(length)).unwrap();
66+
let compiler = wasmer::sys::Singlepass::default();
67+
let store = wasmer::Store::new(compiler);
68+
let module = wasmer::Module::from_binary(&store, &wasm_bytes).unwrap();
69+
group.bench_with_input(format!("length = {length}"), &length, |b, _| {
70+
b.iter_batched(
71+
|| {
72+
let mut store = wasmer::Store::new(wasmer::sys::Singlepass::default());
73+
let instance = wasmer::Instance::new(&mut store, &module, &wasmer::imports! {}).unwrap();
74+
let fun = instance.exports.get_typed_function::<(), ()>(&store, "fun").unwrap();
75+
(store, fun)
76+
},
77+
|(mut store, fun)| {
78+
fun.call(&mut store).unwrap();
79+
},
80+
criterion::BatchSize::LargeInput,
81+
);
82+
});
83+
}
84+
}
85+
5586
criterion_group!(name = memory_copy; config = make_config(); targets = _0001);
5687
criterion_main!(memory_copy);

0 commit comments

Comments
 (0)