1'use strict'; 2const common = require('../common.js'); 3const assert = require('assert'); 4 5const bench = common.createBenchmark(main, { 6 n: [1e6], 7 direction: ['start', 'end'], 8}); 9 10function main({ direction, n }) { 11 const timersList = []; 12 13 bench.start(); 14 if (direction === 'start') { 15 for (let i = 1; i <= n; i++) { 16 timersList.push(setTimeout(cb, i)); 17 } 18 } else { 19 for (let i = n; i > 0; i--) { 20 timersList.push(setTimeout(cb, i)); 21 } 22 } 23 bench.end(n); 24 25 for (let j = 0; j < n; j++) { 26 clearTimeout(timersList[j]); 27 } 28} 29 30function cb() { 31 assert.fail(`Timer ${this._idleTimeout} should not call callback`); 32} 33