Reputation: 1640
Hello I did some simple test: better way to add argument to arguments array-like object in javascript:
This shows that using Array.prototype.push.call is about 3 times slower (chrome), why?
function test() {
Array.prototype.push.call(arguments, 123);
}
function test2() {
arguments[arguments.length] = 123;
arguments.length++;
}
console.time("test1");
for ( var i=0; i<1000000; i++ ) {
test(1,2,3);
}
console.timeEnd("test1");
console.time("test2");
for ( var i=0; i<1000000; i++ ) {
test2(1,2,3);
}
console.timeEnd("test2");
Upvotes: 1
Views: 97
Reputation: 664599
Array.prototype.push.call
is about 3 times slower (chrome), why?
Because
arguments
around requires reification of the object which kills optimisationsUpvotes: 2