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({ direction, n }) {
111cb0ef41Sopenharmony_ci  const timersList = [];
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  bench.start();
141cb0ef41Sopenharmony_ci  if (direction === 'start') {
151cb0ef41Sopenharmony_ci    for (let i = 1; i <= n; i++) {
161cb0ef41Sopenharmony_ci      timersList.push(setTimeout(cb, i));
171cb0ef41Sopenharmony_ci    }
181cb0ef41Sopenharmony_ci  } else {
191cb0ef41Sopenharmony_ci    for (let i = n; i > 0; i--) {
201cb0ef41Sopenharmony_ci      timersList.push(setTimeout(cb, i));
211cb0ef41Sopenharmony_ci    }
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci  bench.end(n);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  for (let j = 0; j < n; j++) {
261cb0ef41Sopenharmony_ci    clearTimeout(timersList[j]);
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cifunction cb() {
311cb0ef41Sopenharmony_ci  assert.fail(`Timer ${this._idleTimeout} should not call callback`);
321cb0ef41Sopenharmony_ci}
33