Files
wasmtime/benches/wasi/read-arguments.wat
Andrew Brown 8426904129 bench: benchmark several common WASI scenarios (#5274)
In order to properly understand the impact of providing thread-safe
implmentations of WASI contexts (#5235), we need benchmarks that measure
the current performance of WASI calls using Wiggle. This change adds
several common WASI scenarios as WAT files (see `benches/wasi/*.wat`)
and benchmarks them with `criterion`. Using `criterion`'s `iter_custom`,
the WAT file runs the desired number of benchmark iterations internally
and the total duration of the runs is divided to get the average time
for each loop iteration.

Why WAT? When compiling these benchmarks from Rust to `wasm32-wasi`, the
output files are large, contain other WASI imports than the desired
ones, and overall it is difficult to tell if we are measuring what we
expect. By hand-writing the WAT, it is (slightly) more clear what each
benchmark is doing.
2022-11-15 17:02:35 -08:00

43 lines
1.9 KiB
Plaintext

(module
(import "wasi_snapshot_preview1" "args_get"
(func $__wasi_args_get (param i32 i32) (result i32)))
(import "wasi_snapshot_preview1" "args_sizes_get"
(func $__wasi_args_sizes_get (param i32 i32) (result i32)))
(func (export "run") (param $iters i64) (result i64)
(local $i i64)
(local.set $i (i64.const 0))
(loop $cont
;; Read the current argument list by:
;; 1) retrieving the argument sizes and then
;; 2) retrieving the argument data itself.
;; Retrieve the sizes of the arguments with parameters:
;; - the address at which to write the number of arguments
;; - the address at which to write the size of the argument buffer
;; Returns an error code.
(call $__wasi_args_sizes_get (i32.const 0) (i32.const 4))
(drop)
;; Read the arguments with parameters:
;; - the address at which to write the array of argument pointers
;; (i.e., one pointer per argument); here we overwrite the size
;; written at address 0
;; - the address at which to write the buffer of argument strings
;; (pointed to by the items written to the first address); we
;; calculate where to start the buffer based on the size of the
;; pointer list (i.e., number of arguments * 4 bytes per pointer)
;; Returns an error code.
(call $__wasi_args_get
(i32.const 0)
(i32.mul (i32.load (i32.const 0)) (i32.const 4)))
(drop)
;; Continue looping until $i reaches $iters.
(local.set $i (i64.add (local.get $i) (i64.const 1)))
(br_if $cont (i64.lt_u (local.get $i) (local.get $iters)))
)
(local.get $i)
)
(memory (export "memory") 1)
)