0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/timers/timers-cancel-unpooled.js
Daniele Belardi de877c5781
benchmark: use let instead of var in timers
PR-URL: https://github.com/nodejs/node/pull/31794
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-03-30 10:16:16 +02:00

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({ 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`);
}