|
1 | 1 | use criterion::{criterion_group, criterion_main, Criterion}; |
2 | 2 | use std::time::Duration; |
3 | 3 |
|
4 | | -/// Number of elements to be filled in the benchmarked table. |
5 | | -const LENGTHS: [usize; 9] = [0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 9_999_999]; |
| 4 | +/// Lengths used for benchmarking. |
| 5 | +const LENGTHS: [usize; 23] = [ |
| 6 | + 0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1_000, 2_000, 5_000, 10_000, 20_000, 50_000, 100_000, 200_000, 500_000, 1_000_000, 2_000_000, 5_000_000, 9_999_999, |
| 7 | +]; |
6 | 8 |
|
7 | 9 | const TEMPLATE: &str = r#" |
8 | 10 | (module |
@@ -58,11 +60,22 @@ fn _0001(c: &mut Criterion) { |
58 | 60 | for length in LENGTHS { |
59 | 61 | let wasm_bytes = wat::parse_str(wat_source(length)).unwrap(); |
60 | 62 | let compiler = wasmer::sys::Singlepass::default(); |
61 | | - let mut store = wasmer::Store::new(compiler); |
| 63 | + let store = wasmer::Store::new(compiler); |
62 | 64 | let module = wasmer::Module::from_binary(&store, &wasm_bytes).unwrap(); |
63 | | - let instance = wasmer::Instance::new(&mut store, &module, &wasmer::imports! {}).unwrap(); |
64 | | - let fun = instance.exports.get_typed_function::<(), ()>(&store, "fun").unwrap(); |
65 | | - group.bench_with_input(format!("length = {length}"), &length, |b, &_| b.iter(|| fun.call(&mut store).unwrap())); |
| 65 | + group.bench_with_input(format!("length = {length}"), &length, |b, _| { |
| 66 | + b.iter_batched( |
| 67 | + || { |
| 68 | + let mut store = wasmer::Store::new(wasmer::sys::Singlepass::default()); |
| 69 | + let instance = wasmer::Instance::new(&mut store, &module, &wasmer::imports! {}).unwrap(); |
| 70 | + let fun = instance.exports.get_typed_function::<(), ()>(&store, "fun").unwrap(); |
| 71 | + (store, fun) |
| 72 | + }, |
| 73 | + |(mut store, fun)| { |
| 74 | + fun.call(&mut store).unwrap(); |
| 75 | + }, |
| 76 | + criterion::BatchSize::LargeInput, |
| 77 | + ); |
| 78 | + }); |
66 | 79 | } |
67 | 80 | } |
68 | 81 |
|
|
0 commit comments