summaryrefslogtreecommitdiff
path: root/benchmark/timers/timers-cancel-unpooled.js
blob: 1daf68bde0ed515c864039241a4c513bd623fc1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
  n: [1e6],
  direction: ['start', 'end']
});

function main({ n, direction }) {

  const timersList = [];
  for (var i = 0; i < n; i++) {
    timersList.push(setTimeout(cb, i + 1));
  }

  var j;
  bench.start();
  if (direction === 'start') {
    for (j = 0; j < n; j++) {
      clearTimeout(timersList[j]);
    }
  } else {
    for (j = n - 1; j >= 0; j--) {
      clearTimeout(timersList[j]);
    }
  }
  bench.end(n);
}

function cb() {
  assert.fail(`Timer ${this._idleTimeout} should not call callback`);
}