Push vs length

JavaScript performance comparison

Revision 18 of this test case created

Info

Array population in javascript - push vs array.length

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
length
var myArray = [];
for(i = 0; i <= 1000; i++){
    myArray[myArray.length - 1] = 'test';
}
 
pending…
push
var myArray = [];
for(i = 0; i <= 1000; i++){
    myArray.push('test');
}
pending…
Direct assignment
var myArray = [];
for(i = 0; i <= 1000; i++){
    myArray[i] = 'test';
}
pending…
Direct assignment (pre-populated)
var myArray = new Array(1000);
for(i = 0; i <= 1000; i++){
    myArray[i] = 'test';
}
pending…
Pre-populated push
var myArray = new Array(1000);
for(i = 0; i <= 1000; i++){
    myArray.push('test');
}
pending…
String Concatenation
var myArray;
var str = 'test';
for(i = 0; i <= 999; i++){
    str += '|test';
}

myArray = str.split('|');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment