repositories
/
benchmarks-js.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Busy wait with a sleep inside.
[benchmarks-js.git]
/
busy-wait.js
diff --git
a/busy-wait.js
b/busy-wait.js
index 5ea20aad653f21df72c89d403b11a57506db2a0b..d49a5fde51981ba870ab4de30397d5e61066592c 100644
(file)
--- a/
busy-wait.js
+++ b/
busy-wait.js
@@
-4,20
+4,26
@@
const { LIST_FORMATTER, sleep } = require('./benchmark-utils')
const suite = new Benchmark.Suite()
const timeout = 2000
const suite = new Benchmark.Suite()
const timeout = 2000
+const interval = 1000
/**
* @param timeoutMs
*/
/**
* @param timeoutMs
*/
-
function dummy
TimeoutBusyWait (timeoutMs) {
+
async function sleep
TimeoutBusyWait (timeoutMs) {
const timeoutTimestampMs = Date.now() + timeoutMs
const timeoutTimestampMs = Date.now() + timeoutMs
- do {} while (Date.now() < timeoutTimestampMs)
+ do {
+ await sleep(interval)
+ } while (Date.now() < timeoutTimestampMs)
}
/**
* @param timeoutMs
* @param intervalMs
*/
}
/**
* @param timeoutMs
* @param intervalMs
*/
-async function divideAndConquerTimeoutBusyWait (timeoutMs, intervalMs = 200) {
+async function divideAndConquerTimeoutBusyWait (
+ timeoutMs,
+ intervalMs = interval
+) {
const tries = Math.round(timeoutMs / intervalMs)
let count = 0
do {
const tries = Math.round(timeoutMs / intervalMs)
let count = 0
do {
@@
-30,7
+36,7
@@
async function divideAndConquerTimeoutBusyWait (timeoutMs, intervalMs = 200) {
* @param timeoutMs
* @param intervalMs
*/
* @param timeoutMs
* @param intervalMs
*/
-function setIntervalTimeoutBusyWait (timeoutMs, intervalMs =
200
) {
+function setIntervalTimeoutBusyWait (timeoutMs, intervalMs =
interval
) {
const tries = Math.round(timeoutMs / intervalMs)
let count = 0
const triesSetInterval = setInterval(() => {
const tries = Math.round(timeoutMs / intervalMs)
let count = 0
const triesSetInterval = setInterval(() => {
@@
-42,8
+48,8
@@
function setIntervalTimeoutBusyWait (timeoutMs, intervalMs = 200) {
}
suite
}
suite
- .add('
dummyTimeoutBusyWait',
function () {
-
dummy
TimeoutBusyWait(timeout)
+ .add('
sleepTimeoutBusyWait', async
function () {
+
sleep
TimeoutBusyWait(timeout)
})
.add('divideAndConquerTimeoutBusyWait', async function () {
await divideAndConquerTimeoutBusyWait(timeout)
})
.add('divideAndConquerTimeoutBusyWait', async function () {
await divideAndConquerTimeoutBusyWait(timeout)