2017-01-21 05:16:26 +08:00
|
|
|
'use strict';
|
2017-09-14 09:48:53 +08:00
|
|
|
const common = require('../common.js');
|
|
|
|
const assert = require('assert');
|
2017-01-21 05:16:26 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2017-11-25 21:07:26 +08:00
|
|
|
millions: [1],
|
2017-01-21 05:16:26 +08:00
|
|
|
});
|
|
|
|
|
2017-12-30 10:56:01 +08:00
|
|
|
function main({ millions }) {
|
|
|
|
const iterations = millions * 1e6;
|
2017-01-21 05:16:26 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const timersList = [];
|
2017-01-21 05:16:26 +08:00
|
|
|
for (var i = 0; i < iterations; i++) {
|
|
|
|
timersList.push(setTimeout(cb, i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var j = 0; j < iterations + 1; j++) {
|
|
|
|
clearTimeout(timersList[j]);
|
|
|
|
}
|
2017-11-25 21:07:26 +08:00
|
|
|
bench.end(iterations / 1e6);
|
2017-01-21 05:16:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cb() {
|
2018-01-23 20:19:14 +08:00
|
|
|
assert.fail(`Timer ${this._idleTimeout} should not call callback`);
|
2017-01-21 05:16:26 +08:00
|
|
|
}
|