1 const Benchmark
= require('benchmark')
2 const { LIST_FORMATTER
} = require('./benchmark-utils')
4 const suite
= new Benchmark
.Suite()
11 function dummyTimeoutBusyWait (timeoutMs
) {
12 const timeoutDateMs
= Date
.now() + timeoutMs
13 do {} while (Date
.now() < timeoutDateMs
)
20 function setIntervalTimeoutBusyWait (timeoutMs
, delayMs
= 200) {
21 const tries
= Math
.round(timeoutMs
/ delayMs
)
23 const triesSetInterval
= setInterval(() => {
25 if (count
=== tries
) {
26 clearInterval(triesSetInterval
)
32 .add('dummyTimeoutBusyWait', function () {
33 dummyTimeoutBusyWait(timeout
)
35 .add('setIntervalTimeoutBusyWait', function () {
36 setIntervalTimeoutBusyWait(timeout
)
38 .on('cycle', function (event
) {
39 console
.log(event
.target
.toString())
41 .on('complete', function () {
43 'Fastest is ' + LIST_FORMATTER
.format(this.filter('fastest').map('name'))
45 // eslint-disable-next-line no-process-exit