mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
ca5f322d32
PR-URL: https://github.com/nodejs/node/pull/46370 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com>
33 lines
647 B
JavaScript
33 lines
647 B
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e6],
|
|
direction: ['start', 'end'],
|
|
});
|
|
|
|
function main({ direction, n }) {
|
|
const timersList = [];
|
|
|
|
bench.start();
|
|
if (direction === 'start') {
|
|
for (let i = 1; i <= n; i++) {
|
|
timersList.push(setTimeout(cb, i));
|
|
}
|
|
} else {
|
|
for (let i = n; i > 0; i--) {
|
|
timersList.push(setTimeout(cb, i));
|
|
}
|
|
}
|
|
bench.end(n);
|
|
|
|
for (let j = 0; j < n; j++) {
|
|
clearTimeout(timersList[j]);
|
|
}
|
|
}
|
|
|
|
function cb() {
|
|
assert.fail(`Timer ${this._idleTimeout} should not call callback`);
|
|
}
|