Skip to content

Commit

Permalink
Add memory bulk-ops benchmark test case (#1074)
Browse files Browse the repository at this point in the history
add bulk-ops benchmark test case
  • Loading branch information
Robbepop authored Jun 17, 2024
1 parent 1823eeb commit c3dc480
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/wasmi/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ criterion_group! {
bench_execute_memory_sum,
bench_execute_memory_fill,
bench_execute_vec_add,
bench_execute_bulk_ops,
}

criterion_main!(
Expand Down Expand Up @@ -1477,3 +1478,20 @@ fn bench_execute_vec_add(c: &mut Criterion) {
)
});
}

fn bench_execute_bulk_ops(c: &mut Criterion) {
const ITERATIONS: i64 = 5_000;
c.bench_function("execute/memory/bulk-ops", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bulk-ops.wat"));
let run = instance
.get_export(&store, "run")
.and_then(Extern::into_func)
.unwrap()
.typed::<i64, i64>(&store)
.unwrap();

b.iter(|| {
run.call(&mut store, ITERATIONS).unwrap();
})
});
}
40 changes: 40 additions & 0 deletions crates/wasmi/benches/wat/bulk-ops.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(module
(memory 8 8)

;; The maximum amount of bytes to process per iteration.
(global $MAX_N i64 (i64.const 250000))

(func (export "run") (param $N i64) (result i64)
(local $i i32)
(local $n i32)
(if (i64.gt_u (local.get $N) (global.get $MAX_N))
(then (unreachable))
)
(local.set $i (i32.const 0))
(local.set $n (i32.wrap_i64 (local.get $N)))
(block $break
(loop $continue
;; if i >= N: break
(br_if $break
(i32.ge_u (local.get $i) (local.get $n))
)
;; mem[0..n].fill(i)
(memory.fill
(i32.const 0) ;; dst
(local.get $i) ;; value
(local.get $n) ;; len
)
;; mem[n..n*2].copy(mem[0..n])
(memory.copy
(local.get $i) ;; dst
(i32.const 0) ;; src
(local.get $n) ;; len
)
;; i += 1
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $continue)
)
)
(i64.const 0)
)
)

0 comments on commit c3dc480

Please sign in to comment.