node/benchmark/timers/timers-cancel-unpooled.js
Antoine du Hamel ca5f322d32
benchmark: add trailing commas
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>
2023-01-29 19:13:35 +01:00

33 lines
648 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({ n, direction }) {
const timersList = [];
for (let i = 0; i < n; i++) {
timersList.push(setTimeout(cb, i + 1));
}
bench.start();
if (direction === 'start') {
for (let j = 0; j < n; j++) {
clearTimeout(timersList[j]);
}
} else {
for (let j = n - 1; j >= 0; j--) {
clearTimeout(timersList[j]);
}
}
bench.end(n);
}
function cb() {
assert.fail(`Timer ${this._idleTimeout} should not call callback`);
}