Keep the dummy busy wait timeout implementation as a reference.
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Jun 2021 18:28:35 +0000 (20:28 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 8 Jun 2021 18:28:35 +0000 (20:28 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
busy-wait.js

index d49a5fde51981ba870ab4de30397d5e61066592c..7c8273e76e94f734ecb5e69144c2271c10953c23 100644 (file)
@@ -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)
   })