parent
0b387e3940
commit
5e9a018b23
|
@ -0,0 +1,61 @@
|
||||||
|
var Benchmark = require('benchmark');
|
||||||
|
var benchmarks = require('beautify-benchmark');
|
||||||
|
|
||||||
|
var suite = new Benchmark.Suite();
|
||||||
|
|
||||||
|
function slice() {
|
||||||
|
return Array.prototype.slice.call(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function slice0() {
|
||||||
|
return Array.prototype.slice.call(arguments, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function forLoop() {
|
||||||
|
var args = new Array(arguments.length);
|
||||||
|
for(var i = 0; i < args.length; i++) {
|
||||||
|
args[i] = arguments[i];
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('slice(0, 1, 2, 3, 4, 5, 6, 7): %j', slice(0, 1, 2, 3, 4, 5, 6, 7));
|
||||||
|
console.log('slice0(0, 1, 2, 3, 4, 5, 6, 7): %j', slice0(0, 1, 2, 3, 4, 5, 6, 7));
|
||||||
|
console.log('forLoop(0, 1, 2, 3, 4, 5, 6, 7): %j', forLoop(0, 1, 2, 3, 4, 5, 6, 7));
|
||||||
|
|
||||||
|
suite
|
||||||
|
|
||||||
|
.add('Array.prototype.slice.call(arguments)', function() {
|
||||||
|
slice(0, 1, 2, 3, 4, 5, 6, 7)
|
||||||
|
})
|
||||||
|
.add('Array.prototype.slice.call(arguments, 0)', function() {
|
||||||
|
slice0(0, 1, 2, 3, 4, 5, 6, 7)
|
||||||
|
})
|
||||||
|
.add('for(var i = 0; i < args.length; i++) {}', function() {
|
||||||
|
forLoop(0, 1, 2, 3, 4, 5, 6, 7)
|
||||||
|
})
|
||||||
|
|
||||||
|
.on('cycle', function(event) {
|
||||||
|
benchmarks.add(event.target);
|
||||||
|
})
|
||||||
|
.on('start', function(event) {
|
||||||
|
console.log('\n arguments to args Benchmark\n node version: %s, date: %s\n Starting...',
|
||||||
|
process.version, Date());
|
||||||
|
})
|
||||||
|
.on('complete', function done() {
|
||||||
|
benchmarks.log();
|
||||||
|
})
|
||||||
|
.run({ async: false });
|
||||||
|
|
||||||
|
// slice(0, 1, 2, 3, 4, 5, 6, 7): [0,1,2,3,4,5,6,7]
|
||||||
|
// slice0(0, 1, 2, 3, 4, 5, 6, 7): [0,1,2,3,4,5,6,7]
|
||||||
|
// forLoop(0, 1, 2, 3, 4, 5, 6, 7): [0,1,2,3,4,5,6,7]
|
||||||
|
//
|
||||||
|
// arguments to args Benchmark
|
||||||
|
// node version: v2.4.0, date: Tue Jul 21 2015 01:39:54 GMT+0800 (CST)
|
||||||
|
// Starting...
|
||||||
|
// 3 tests completed.
|
||||||
|
//
|
||||||
|
// Array.prototype.slice.call(arguments) x 4,537,649 ops/sec ±1.18% (94 runs sampled)
|
||||||
|
// Array.prototype.slice.call(arguments, 0) x 4,605,132 ops/sec ±0.87% (96 runs sampled)
|
||||||
|
// for(var i = 0; i < args.length; i++) {} x 30,435,436 ops/sec ±0.91% (93 runs sampled)
|
5
index.js
5
index.js
|
@ -133,8 +133,11 @@ module.exports = function (app, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// __(key, value1, value2, value3, value4, value5, ...)
|
// __(key, value1, value2, value3, value4, value5, ...)
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = new Array(arguments.length);
|
||||||
args[0] = text;
|
args[0] = text;
|
||||||
|
for(var i = 1; i < args.length; i++) {
|
||||||
|
args[i] = arguments[i];
|
||||||
|
}
|
||||||
return util.format.apply(util, args);
|
return util.format.apply(util, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,16 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "~2.2.0",
|
"debug": "~2.2.0",
|
||||||
"humanize-ms": "~1.0.1",
|
"humanize-ms": "~1.0.1",
|
||||||
"ini": "~1.3.3"
|
"ini": "~1.3.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autod": "*",
|
"autod": "*",
|
||||||
|
"beautify-benchmark": "~0.2.4",
|
||||||
|
"benchmark": "~1.0.0",
|
||||||
"contributors": "*",
|
"contributors": "*",
|
||||||
"istanbul-harmony": "*",
|
"istanbul-harmony": "*",
|
||||||
"jshint": "*",
|
"jshint": "*",
|
||||||
"koa": "~0.20.0",
|
"koa": "~0.21.0",
|
||||||
"mm": "~1.1.0",
|
"mm": "~1.1.0",
|
||||||
"mocha": "*",
|
"mocha": "*",
|
||||||
"pedding": "~1.0.0",
|
"pedding": "~1.0.0",
|
||||||
|
|
Loading…
Reference in New Issue