ElSajko
ElSajko

Reputation: 1640

Add argument to 'arguments' array-like object, performance test

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?

http://jsfiddle.net/vhrs56nm/

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

Answers (1)

Bergi
Bergi

Reputation: 664599

Array.prototype.push.call is about 3 times slower (chrome), why?

Because

Upvotes: 2

Related Questions