From: Jérôme Benoit Date: Sun, 23 Apr 2023 00:21:55 +0000 (+0200) Subject: Use monotonic timer X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=41672b128b0270f3f6c72a8ed3d69d0bea0ad366;p=benchmarks-js.git Use monotonic timer Signed-off-by: Jérôme Benoit --- diff --git a/busy-wait.js b/busy-wait.js index 66d5896..9c392a5 100644 --- a/busy-wait.js +++ b/busy-wait.js @@ -8,9 +8,9 @@ const interval = 1000 * @param timeoutMs */ function dummyTimeoutBusyWait (timeoutMs) { - const timeoutTimestampMs = Date.now() + timeoutMs + const timeoutTimestampMs = performance.now() + timeoutMs // eslint-disable-next-line no-empty - do {} while (Date.now() < timeoutTimestampMs) + do {} while (performance.now() < timeoutTimestampMs) } /** @@ -18,10 +18,10 @@ function dummyTimeoutBusyWait (timeoutMs) { * @param intervalMs */ async function sleepTimeoutBusyWait (timeoutMs, intervalMs = interval) { - const timeoutTimestampMs = Date.now() + timeoutMs + const timeoutTimestampMs = performance.now() + timeoutMs do { await sleep(intervalMs) - } while (Date.now() < timeoutTimestampMs) + } while (performance.now() < timeoutTimestampMs) } /**