Push vs length

JavaScript performance comparison

Revision 7 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 (var i = 0; i < 100000; i++) {
  myArray[myArray.length] = 'fo<LOLOLOLO>FWEAFAWFDUIW#AHFAWO#IHIFA#o';
  myArray[myArray.length] = 'barafhawl38fyaw38o7flahfr79a3rwh7oalw7r';
}
myArray.join("");
pending…
push
var myArray = [];

for (var i = 0; i < 100000; i++) {
  myArray.push('fo<LOLOLOLO>FWEAFAWFDUIW#AHFAWO#IHIFA#o');
  myArray.push('barafhawl38fyaw38o7flahfr79a3rwh7oalw7r');
}
myArray.join("");
pending…
append
var str = "";

for (var i = 0; i < 100000; i++) {
  str += 'fo<LOLOLOLO>FWEAFAWFDUIW#AHFAWO#IHIFA#o';
  str += 'barafhawl38fyaw38o7flahfr79a3rwh7oalw7r';
}
pending…
Preallocated
var myArray = new Array(100000);

for (var i = 0; i < 100000; i++) {
  myArray[i] = 'fo<LOLOLOLO>FWEAFAWFDUIW#AHFAWO#IHIFA#o';
  myArray[i] = 'barafhawl38fyaw38o7flahfr79a3rwh7oalw7r';
}
myArray.join("");
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