Created
August 9, 2011 01:46
-
-
Save chjj/1133253 to your computer and use it in GitHub Desktop.
slice arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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