• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4const bench = common.createBenchmark(main, {
5  n: [1e6],
6});
7
8function main({ n }) {
9  let j = 0;
10  function cb1(arg1) {
11    j++;
12    if (j === n)
13      bench.end(n);
14  }
15
16  function cb2(arg1, arg2) {
17    j++;
18    if (j === n)
19      bench.end(n);
20  }
21
22  function cb3(arg1, arg2, arg3) {
23    j++;
24    if (j === n)
25      bench.end(n);
26  }
27
28  function cb4(arg1, arg2, arg3, arg4) {
29    j++;
30    if (j === n)
31      bench.end(n);
32  }
33
34  bench.start();
35  for (let i = 0; i < n; i++) {
36    if (i % 4 === 0)
37      setTimeout(cb4, 1, 3.14, 1024, true, false);
38    else if (i % 3 === 0)
39      setTimeout(cb3, 1, 512, true, null);
40    else if (i % 2 === 0)
41      setTimeout(cb2, 1, false, 5.1);
42    else
43      setTimeout(cb1, 1, 0);
44  }
45}
46