11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci n: [1e6], 71cb0ef41Sopenharmony_ci direction: ['start', 'end'], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction main({ n, direction }) { 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci const timersList = []; 131cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 141cb0ef41Sopenharmony_ci timersList.push(setTimeout(cb, i + 1)); 151cb0ef41Sopenharmony_ci } 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci bench.start(); 181cb0ef41Sopenharmony_ci if (direction === 'start') { 191cb0ef41Sopenharmony_ci for (let j = 0; j < n; j++) { 201cb0ef41Sopenharmony_ci clearTimeout(timersList[j]); 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci } else { 231cb0ef41Sopenharmony_ci for (let j = n - 1; j >= 0; j--) { 241cb0ef41Sopenharmony_ci clearTimeout(timersList[j]); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci bench.end(n); 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cifunction cb() { 311cb0ef41Sopenharmony_ci assert.fail(`Timer ${this._idleTimeout} should not call callback`); 321cb0ef41Sopenharmony_ci} 33