11use criterion:: { criterion_group, criterion_main, Criterion } ;
22use std:: time:: Duration ;
33
4- /// Sizes of data segments used for memory initialization during benchmarking.
5- const FILL_SIZES : [ usize ; 11 ] = [
4+ /// Lengths used for benchmarking.
5+ const LENGTHS : [ usize ; 30 ] = [
66 1 ,
7+ 2 ,
8+ 5 ,
9+ 10 ,
10+ 20 ,
11+ 50 ,
712 100 ,
13+ 200 ,
14+ 500 ,
815 1_000 ,
16+ 2_000 ,
17+ 5_000 ,
918 10_000 ,
19+ 20_000 ,
20+ 50_000 ,
1021 100_000 ,
22+ 200_000 ,
23+ 500_000 ,
1124 1_000_000 ,
25+ 2_000_000 ,
26+ 5_000_000 ,
1227 10_000_000 ,
28+ 20_000_000 ,
29+ 50_000_000 ,
1330 100_000_000 ,
31+ 200_000_000 ,
32+ 500_000_000 ,
1433 1_000_000_000 ,
1534 2_000_000_000 ,
1635 4_000_000_000 ,
@@ -42,16 +61,16 @@ fn make_config() -> Criterion {
4261
4362/// Checks if the benchmarked Wasm code works.
4463fn precheck ( ) {
45- for size in FILL_SIZES {
46- let wasm_bytes = wat:: parse_str ( wat_source ( size ) ) . unwrap ( ) ;
64+ for length in LENGTHS {
65+ let wasm_bytes = wat:: parse_str ( wat_source ( length ) ) . unwrap ( ) ;
4766 let compiler = wasmer:: sys:: Singlepass :: default ( ) ;
4867 let mut store = wasmer:: Store :: new ( compiler) ;
4968 let module = wasmer:: Module :: from_binary ( & store, & wasm_bytes) . unwrap ( ) ;
5069 let instance = wasmer:: Instance :: new ( & mut store, & module, & wasmer:: imports! { } ) . unwrap ( ) ;
5170 let memory = instance. exports . get_memory ( "mem" ) . unwrap ( ) ;
5271 let fun = instance. exports . get_typed_function :: < ( ) , ( ) > ( & store, "fun" ) . unwrap ( ) ;
5372 fun. call ( & mut store) . unwrap ( ) ;
54- let start_index = size . saturating_sub ( 1 ) as u64 ;
73+ let start_index = length . saturating_sub ( 1 ) as u64 ;
5574 let data = memory. view ( & store) . copy_range_to_vec ( start_index..( start_index + 2 ) ) . unwrap ( ) ;
5675 assert_eq ! ( vec![ 65 , 0 ] , data) ;
5776 }
@@ -60,14 +79,25 @@ fn precheck() {
6079fn _0001 ( c : & mut Criterion ) {
6180 precheck ( ) ;
6281 let mut group = c. benchmark_group ( "memory-fill" ) ;
63- for size in FILL_SIZES {
64- let wasm_bytes = wat:: parse_str ( wat_source ( size ) ) . unwrap ( ) ;
82+ for length in LENGTHS {
83+ let wasm_bytes = wat:: parse_str ( wat_source ( length ) ) . unwrap ( ) ;
6584 let compiler = wasmer:: sys:: Singlepass :: default ( ) ;
66- let mut store = wasmer:: Store :: new ( compiler) ;
85+ let store = wasmer:: Store :: new ( compiler) ;
6786 let module = wasmer:: Module :: from_binary ( & store, & wasm_bytes) . unwrap ( ) ;
68- let instance = wasmer:: Instance :: new ( & mut store, & module, & wasmer:: imports! { } ) . unwrap ( ) ;
69- let fun = instance. exports . get_typed_function :: < ( ) , ( ) > ( & store, "fun" ) . unwrap ( ) ;
70- group. bench_with_input ( format ! ( "size = {size}" ) , & size, |b, & _| b. iter ( || fun. call ( & mut store) . unwrap ( ) ) ) ;
87+ group. bench_with_input ( format ! ( "length = {length}" ) , & length, |b, _| {
88+ b. iter_batched (
89+ || {
90+ let mut store = wasmer:: Store :: new ( wasmer:: sys:: Singlepass :: default ( ) ) ;
91+ let instance = wasmer:: Instance :: new ( & mut store, & module, & wasmer:: imports! { } ) . unwrap ( ) ;
92+ let fun = instance. exports . get_typed_function :: < ( ) , ( ) > ( & store, "fun" ) . unwrap ( ) ;
93+ ( store, fun)
94+ } ,
95+ |( mut store, fun) | {
96+ fun. call ( & mut store) . unwrap ( ) ;
97+ } ,
98+ criterion:: BatchSize :: LargeInput ,
99+ ) ;
100+ } ) ;
71101 }
72102}
73103
0 commit comments