From a6c343813ea719afaeeda19eb2126550bf5b6085 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Jun 2021 20:28:35 +0200 Subject: [PATCH] Keep the dummy busy wait timeout implementation as a reference. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- busy-wait.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/busy-wait.js b/busy-wait.js index d49a5fd..7c8273e 100644 --- a/busy-wait.js +++ b/busy-wait.js @@ -6,6 +6,14 @@ const suite = new Benchmark.Suite() const timeout = 2000 const interval = 1000 +/** + * @param timeoutMs + */ +function dummyTimeoutBusyWait (timeoutMs) { + const timeoutTimestampMs = Date.now() + timeoutMs + do {} while (Date.now() < timeoutTimestampMs) +} + /** * @param timeoutMs */ @@ -48,6 +56,9 @@ function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = interval) { } suite + .add('dummyTimeoutBusyWait', function () { + dummyTimeoutBusyWait(timeout) + }) .add('sleepTimeoutBusyWait', async function () { sleepTimeoutBusyWait(timeout) }) -- 2.34.1