2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2014-11-29 13:50:29 +01:00
|
|
|
var common = require('../common.js');
|
|
|
|
var domain = require('domain');
|
|
|
|
|
|
|
|
var bench = common.createBenchmark(main, {
|
|
|
|
arguments: [0, 1, 2, 3],
|
|
|
|
n: [10]
|
|
|
|
});
|
|
|
|
|
|
|
|
var bdomain = domain.create();
|
|
|
|
var gargs = [1, 2, 3];
|
|
|
|
|
|
|
|
function main(conf) {
|
|
|
|
|
2016-02-25 07:30:10 +01:00
|
|
|
var args, n = +conf.n;
|
2016-02-20 02:03:16 +01:00
|
|
|
var myArguments = gargs.slice(0, conf.arguments);
|
2014-11-29 13:50:29 +01:00
|
|
|
bench.start();
|
|
|
|
|
|
|
|
bdomain.enter();
|
|
|
|
for (var i = 0; i < n; i++) {
|
2016-02-20 02:03:16 +01:00
|
|
|
if (myArguments.length >= 2) {
|
|
|
|
args = Array.prototype.slice.call(myArguments, 1);
|
2016-03-02 22:38:23 +01:00
|
|
|
fn.apply(this, args);
|
2014-11-29 13:50:29 +01:00
|
|
|
} else {
|
2016-03-02 22:38:23 +01:00
|
|
|
fn.call(this);
|
2014-11-29 13:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bdomain.exit();
|
|
|
|
|
|
|
|
bench.end(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fn(a, b, c) {
|
|
|
|
if (!a)
|
|
|
|
a = 1;
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
b = 2;
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
c = 3;
|
|
|
|
|
|
|
|
return a + b + c;
|
2016-02-25 07:30:10 +01:00
|
|
|
}
|