1'use strict'; 2 3const common = require('../common.js'); 4const bench = common.createBenchmark(main, { 5 n: [7e6] 6}); 7 8function main({ n }) { 9 let counter = n; 10 function cb4(arg1, arg2, arg3, arg4) { 11 if (--counter) { 12 if (counter % 4 === 0) 13 process.nextTick(cb4, 3.14, 1024, true, false); 14 else if (counter % 3 === 0) 15 process.nextTick(cb3, 512, true, null); 16 else if (counter % 2 === 0) 17 process.nextTick(cb2, false, 5.1); 18 else 19 process.nextTick(cb1, 0); 20 } else 21 bench.end(n); 22 } 23 24 function cb3(arg1, arg2, arg3) { 25 if (--counter) { 26 if (counter % 4 === 0) 27 process.nextTick(cb4, 3.14, 1024, true, false); 28 else if (counter % 3 === 0) 29 process.nextTick(cb3, 512, true, null); 30 else if (counter % 2 === 0) 31 process.nextTick(cb2, false, 5.1); 32 else 33 process.nextTick(cb1, 0); 34 } else 35 bench.end(n); 36 } 37 38 function cb2(arg1, arg2) { 39 if (--counter) { 40 if (counter % 4 === 0) 41 process.nextTick(cb4, 3.14, 1024, true, false); 42 else if (counter % 3 === 0) 43 process.nextTick(cb3, 512, true, null); 44 else if (counter % 2 === 0) 45 process.nextTick(cb2, false, 5.1); 46 else 47 process.nextTick(cb1, 0); 48 } else 49 bench.end(n); 50 } 51 52 function cb1(arg1) { 53 if (--counter) { 54 if (counter % 4 === 0) 55 process.nextTick(cb4, 3.14, 1024, true, false); 56 else if (counter % 3 === 0) 57 process.nextTick(cb3, 512, true, null); 58 else if (counter % 2 === 0) 59 process.nextTick(cb2, false, 5.1); 60 else 61 process.nextTick(cb1, 0); 62 } else 63 bench.end(n); 64 } 65 bench.start(); 66 process.nextTick(cb1, true); 67} 68