Files
wasmtime/benches/wasi/get-current-time.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

23 lines
955 B
Plaintext

(module
(import "wasi_snapshot_preview1" "clock_time_get"
(func $__wasi_clock_time_get (param i32 i64 i32) (result i32)))
(func (export "run") (param $iters i64) (result i64)
(local $i i64)
(local.set $i (i64.const 0))
(loop $cont
;; Retrieve the current time with the following parameters:
;; - $clockid: here we use the enum value for $realtime
;; - $precision: the maximum lag, which we set to 0 here
;; - the address at which to write the u64 $timestamp
;; Returns an error code.
(call $__wasi_clock_time_get (i32.const 1) (i64.const 0) (i32.const 0))
(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)
)