Skip to content

Instantly share code, notes, and snippets.

@chjj
Created August 9, 2011 01:46
Show Gist options
  • Save chjj/1133253 to your computer and use it in GitHub Desktop.
Save chjj/1133253 to your computer and use it in GitHub Desktop.
slice arguments
(function() {
var bench = function(func, t) {
var start = new Date()
, i = t || 100000;
while (i--) func(1, 2, 3);
console.log('%s: %sms', func.name, new Date() - start);
};
var slice = Array.prototype.slice;
bench(function _slice() {
var args = slice.call(arguments);
args.unshift(1);
});
bench(function _for() {
var l = arguments.length;
var args = new Array(l + 1);
args[0] = 1;
for (var i = 0; i < l; i++) args[i+1] = arguments[i];
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment