summaryrefslogtreecommitdiff
path: root/benchmark/process/next-tick-depth-args.js
blob: da61f90a64727883dece2f430ab92f74a052d648 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';

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

function main({ n }) {
  let counter = n;
  function cb4(arg1, arg2, arg3, arg4) {
    if (--counter) {
      if (counter % 4 === 0)
        process.nextTick(cb4, 3.14, 1024, true, false);
      else if (counter % 3 === 0)
        process.nextTick(cb3, 512, true, null);
      else if (counter % 2 === 0)
        process.nextTick(cb2, false, 5.1);
      else
        process.nextTick(cb1, 0);
    } else
      bench.end(n);
  }
  function cb3(arg1, arg2, arg3) {
    if (--counter) {
      if (counter % 4 === 0)
        process.nextTick(cb4, 3.14, 1024, true, false);
      else if (counter % 3 === 0)
        process.nextTick(cb3, 512, true, null);
      else if (counter % 2 === 0)
        process.nextTick(cb2, false, 5.1);
      else
        process.nextTick(cb1, 0);
    } else
      bench.end(n);
  }
  function cb2(arg1, arg2) {
    if (--counter) {
      if (counter % 4 === 0)
        process.nextTick(cb4, 3.14, 1024, true, false);
      else if (counter % 3 === 0)
        process.nextTick(cb3, 512, true, null);
      else if (counter % 2 === 0)
        process.nextTick(cb2, false, 5.1);
      else
        process.nextTick(cb1, 0);
    } else
      bench.end(n);
  }
  function cb1(arg1) {
    if (--counter) {
      if (counter % 4 === 0)
        process.nextTick(cb4, 3.14, 1024, true, false);
      else if (counter % 3 === 0)
        process.nextTick(cb3, 512, true, null);
      else if (counter % 2 === 0)
        process.nextTick(cb2, false, 5.1);
      else
        process.nextTick(cb1, 0);
    } else
      bench.end(n);
  }
  bench.start();
  process.nextTick(cb1, true);
}