tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

time.Now in wasi doesn't seem to use monotonic clock

Open codefromthecrypt opened this issue 2 years ago • 1 comments

I would expect time.Now to return a monotonic clock reading, so that time.Since duration can be precise. However, I traced it when building to wasi, and it seems only the wall time is being fetched. Any ideas?

$ cat main.go
package main

import "time"

func main() {
	t := time.Now()
	println(time.Since(t))
}
$ tinygo version
tinygo version 0.28.0-dev-5c2753e darwin/amd64 (using go version go1.20.4 and LLVM version 15.0.0)
$ tinygo build -target=wasi -o main.wasm .
$ wazero version
1.2.0

$ wazero run -hostlogging=all main.wasm 
--> ._start()
	==> wasi_snapshot_preview1.clock_time_get(id=realtime,precision=1000)
	<== (timestamp=1686451876272879000,errno=ESUCCESS)
	==> wasi_snapshot_preview1.clock_time_get(id=realtime,precision=1000)
	<== (timestamp=1686451876272883000,errno=ESUCCESS)
4000
	--> .asyncify_start_unwind(66396)
	<--
	--> .asyncify_stop_unwind()
	<--
<--

codefromthecrypt avatar Jun 11 '23 02:06 codefromthecrypt