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
Anatoli Papirovski 23a56e0c28
timers: use only a single TimerWrap instance
Hang all timer lists off a single TimerWrap and use the PriorityQueue
to manage expiration priorities. This makes the Timers code clearer,
consumes significantly less resources and improves performance.

PR-URL: https://github.com/nodejs/node/pull/20555
Fixes: https://github.com/nodejs/node/issues/16105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-05-22 23:26:12 +04:00

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