From 41672b128b0270f3f6c72a8ed3d69d0bea0ad366 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 23 Apr 2023 02:21:55 +0200 Subject: [PATCH] Use monotonic timer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- busy-wait.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) } /** -- 2.34.1