Assuming the "perfomance delay" described by Jan Juna, I have tried this simple script to check if there are any differences in terms of throughput:
Interval:
const max = 50;
const timer = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 100, 150, 200, 250, 300, 400, 500];
function crono(timer) {
return new Promise(resolve => {
const exit = [];
let i = 0
setInterval(() => i++, timer);
setInterval(() => {
exit.push(i);
i = 0;
if (exit.length === max) {
const sum = exit.reduce((a, b) => (a + b), 0);
const avg = sum / exit.length;
console.log(`${timer} = ${avg}`);
resolve(avg)
}
}, 1000);
});
}
Promise.all(timer.map(crono)).then(process.exit);
Timeout:
const max = 50;
const timer = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 100, 150, 200, 250, 300, 400, 500];
function crono(timer) {
return new Promise(resolve => {
const exit = [];
let i = 0
const redo = () => {
i++
setTimeout(redo, timer);
}
setInterval(() => {
exit.push(i);
i = 0;
if (exit.length === max) {
const sum = exit.reduce((a, b) => (a + b), 0);
const avg = sum / exit.length;
console.log(`${timer} = ${avg}`);
resolve(x)
}
}, 1000);
redo();
});
}
Promise.all(timer.map(crono)).then(process.exit);
And this is the output vith nodejs 8.11: that shows no difference in terms of throughput:
