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({ n, direction }) { 11 12 const timersList = []; 13 for (let i = 0; i < n; i++) { 14 timersList.push(setTimeout(cb, i + 1)); 15 } 16 17 bench.start(); 18 if (direction === 'start') { 19 for (let j = 0; j < n; j++) { 20 clearTimeout(timersList[j]); 21 } 22 } else { 23 for (let j = n - 1; j >= 0; j--) { 24 clearTimeout(timersList[j]); 25 } 26 } 27 bench.end(n); 28} 29 30function cb() { 31 assert.fail(`Timer ${this._idleTimeout} should not call callback`); 32} 33