Push vs length (v7)

Revision 7 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/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("");
ready
push
var myArray = [];

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

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

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.