The WASI function clock_time_get is meant to return nanosecond precision, but Emscripten's implementation uses Date.now() in realtime mode rather than performance.now(). The latter can at best only do microsecond precision, but that's much better than the former's millisecond precision. (Browsers will typically restrict it to 100 microsec precision, but that's still 10 times better than Date.now(). Node should get the full microsec detail.)
I'm sure there are lots of tricky edge cases here which I don't know about, but this seems like it should be broadly possible?
|
if (clk_id === {{{ cDefs.__WASI_CLOCKID_REALTIME }}}) { |
|
now = _emscripten_date_now(); |
|
} else if (nowIsMonotonic) { |
|
now = _emscripten_get_now(); |
Something like this?
if (clk_id === {{{ cDefs.__WASI_CLOCKID_REALTIME }}}) {
now = performance.timeOrigin + _emscripten_get_now();
}
The WASI function clock_time_get is meant to return nanosecond precision, but Emscripten's implementation uses
Date.now()in realtime mode rather thanperformance.now(). The latter can at best only do microsecond precision, but that's much better than the former's millisecond precision. (Browsers will typically restrict it to 100 microsec precision, but that's still 10 times better thanDate.now(). Node should get the full microsec detail.)I'm sure there are lots of tricky edge cases here which I don't know about, but this seems like it should be broadly possible?
emscripten/src/lib/libwasi.js
Lines 164 to 167 in 7080730
Something like this?