summaryrefslogtreecommitdiff
path: root/deps/node/benchmark/process/next-tick-breadth-args.js
blob: 6baa8d9960903006a375958953335cca7f41ab84 (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
34
35
36
37
38
39
40
41
42
43
'use strict';

const common = require('../common.js');
const bench = common.createBenchmark(main, {
  n: [4e6]
});

function main({ n }) {
  var j = 0;

  function cb1(arg1) {
    j++;
    if (j === n)
      bench.end(n);
  }
  function cb2(arg1, arg2) {
    j++;
    if (j === n)
      bench.end(n);
  }
  function cb3(arg1, arg2, arg3) {
    j++;
    if (j === n)
      bench.end(n);
  }
  function cb4(arg1, arg2, arg3, arg4) {
    j++;
    if (j === n)
      bench.end(n);
  }

  bench.start();
  for (var i = 0; i < n; i++) {
    if (i % 4 === 0)
      process.nextTick(cb4, 3.14, 1024, true, false);
    else if (i % 3 === 0)
      process.nextTick(cb3, 512, true, null);
    else if (i % 2 === 0)
      process.nextTick(cb2, false, 5.1);
    else
      process.nextTick(cb1, 0);
  }
}