4742018a698db86fb50aadb5656d42fde29d8f56
1 const Benchmark
= require('benchmark')
2 const { LIST_FORMATTER
} = require('./benchmark-utils')
4 const suite
= new Benchmark
.Suite()
8 function dummyTimeoutBusyWait (timeoutMs
) {
9 const timeoutDateMs
= Date
.now() + timeoutMs
10 do {} while (Date
.now() < timeoutDateMs
)
13 function setIntervalTimeoutBusyWait (timeoutMs
, delayMs
= 200) {
14 const tries
= Math
.round(timeoutMs
/ delayMs
)
16 const triesSetInterval
= setInterval(() => {
18 if (count
=== tries
) {
19 clearInterval(triesSetInterval
)
25 .add('dummyTimeoutBusyWait', function () {
26 dummyTimeoutBusyWait(timeout
)
28 .add('setIntervalTimeoutBusyWait', function () {
29 setIntervalTimeoutBusyWait(timeout
)
31 .on('cycle', function (event
) {
32 console
.log(event
.target
.toString())
34 .on('complete', function () {
36 'Fastest is ' + LIST_FORMATTER
.format(this.filter('fastest').map('name'))
38 // eslint-disable-next-line no-process-exit