2015-05-01 14:08:02 -04:00
|
|
|
'use strict';
|
|
|
|
|
2017-09-13 22:48:53 -03:00
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
2023-02-05 12:00:09 +01:00
|
|
|
n: [1e7],
|
2015-05-01 14:08:02 -04:00
|
|
|
});
|
|
|
|
|
2018-03-17 20:49:09 +05:30
|
|
|
function main({ n }) {
|
2020-01-31 16:50:00 +01:00
|
|
|
let j = 0;
|
2015-05-01 14:08:02 -04:00
|
|
|
|
|
|
|
function cb1(arg1) {
|
2018-03-17 20:49:09 +05:30
|
|
|
j++;
|
|
|
|
if (j === n)
|
|
|
|
bench.end(n);
|
2015-05-01 14:08:02 -04:00
|
|
|
}
|
2019-11-27 22:56:21 -08:00
|
|
|
|
2015-05-01 14:08:02 -04:00
|
|
|
function cb2(arg1, arg2) {
|
2018-03-17 20:49:09 +05:30
|
|
|
j++;
|
|
|
|
if (j === n)
|
|
|
|
bench.end(n);
|
2015-05-01 14:08:02 -04:00
|
|
|
}
|
2019-11-27 22:56:21 -08:00
|
|
|
|
2015-05-01 14:08:02 -04:00
|
|
|
function cb3(arg1, arg2, arg3) {
|
2018-03-17 20:49:09 +05:30
|
|
|
j++;
|
|
|
|
if (j === n)
|
|
|
|
bench.end(n);
|
2015-05-01 14:08:02 -04:00
|
|
|
}
|
2019-11-27 22:56:21 -08:00
|
|
|
|
2017-08-05 22:08:59 -07:00
|
|
|
function cb4(arg1, arg2, arg3, arg4) {
|
2018-03-17 20:49:09 +05:30
|
|
|
j++;
|
|
|
|
if (j === n)
|
|
|
|
bench.end(n);
|
2017-08-05 22:08:59 -07:00
|
|
|
}
|
2015-05-01 14:08:02 -04:00
|
|
|
|
|
|
|
bench.start();
|
2019-07-31 08:26:38 -05:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-08-05 22:08:59 -07:00
|
|
|
if (i % 4 === 0)
|
|
|
|
process.nextTick(cb4, 3.14, 1024, true, false);
|
|
|
|
else if (i % 3 === 0)
|
2015-05-01 14:08:02 -04:00
|
|
|
process.nextTick(cb3, 512, true, null);
|
|
|
|
else if (i % 2 === 0)
|
|
|
|
process.nextTick(cb2, false, 5.1);
|
|
|
|
else
|
|
|
|
process.nextTick(cb1, 0);
|
|
|
|
}
|
|
|
|
}
|