clock_gettime has two problems.
- var now = Date.now();
- {{{ makeSetValue('tp', '___timespec_struct_layout.tv_sec', 'Math.floor(now/1000)', 'i32') }}}; // seconds
- {{{ makeSetValue('tp', '___timespec_struct_layout.tv_nsec', '0', 'i32') }}}; // nanoseconds - not supported
----
+ var now, msec, fmsec;
+ if (clk_id == CLOCK_REALTIME) {
+ now = Date.now();
+ } else {
+ now = performance.now();
+ }
+ msec = Math.floor(now);
+ fmsec = now - msec;
+ {{{ makeSetValue('tp', '___timespec_struct_layout.tv_sec', 'msec/1000', 'i32') }}}; // seconds
+ {{{ makeSetValue('tp', '___timespec_struct_layout.tv_nsec', 'fmsec*1000', 'i32') }}}; // nanoseconds
I'm not sure how widespread support is for the high resolution timer (performance.now()).
clock_gettime has two problems.
Something like the following change should be made
I'm not sure how widespread support is for the high resolution timer (performance.now()).