2017-01-20 22:16:26 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
|
|
|
const assert = require('assert');
|
2017-01-20 22:16:26 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2018-03-17 16:19:09 +01:00
|
|
|
n: [1e6],
|
2018-05-05 19:50:21 +02:00
|
|
|
direction: ['start', 'end']
|
2017-01-20 22:16:26 +01:00
|
|
|
});
|
|
|
|
|
2018-05-05 19:50:21 +02:00
|
|
|
function main({ n, direction }) {
|
2017-01-20 22:16:26 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const timersList = [];
|
2019-07-31 15:26:38 +02:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-01-20 22:16:26 +01:00
|
|
|
timersList.push(setTimeout(cb, i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
2018-05-05 19:50:21 +02:00
|
|
|
if (direction === 'start') {
|
2020-02-14 13:13:58 +01:00
|
|
|
for (let j = 0; j < n; j++) {
|
2018-05-05 19:50:21 +02:00
|
|
|
clearTimeout(timersList[j]);
|
|
|
|
}
|
|
|
|
} else {
|
2020-02-14 13:13:58 +01:00
|
|
|
for (let j = n - 1; j >= 0; j--) {
|
2018-05-05 19:50:21 +02:00
|
|
|
clearTimeout(timersList[j]);
|
|
|
|
}
|
2017-01-20 22:16:26 +01:00
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2017-01-20 22:16:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function cb() {
|
2018-01-23 13:19:14 +01:00
|
|
|
assert.fail(`Timer ${this._idleTimeout} should not call callback`);
|
2017-01-20 22:16:26 +01:00
|
|
|
}
|