Array push() vs unshift() vs direct assignment (in WHILE loop, 1000 iterations) (v18)

Revision 18 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
push
var i = 0;
var a = [];
while (i < 100000) {
  a.push("Some short unique string " + i);
  i++;
}
ready
unshift
var i = 0;
var a = [];
while (i < 100000) {
  a.unshift("Some short unique string " + i);
  i++;
}
ready
Direct Assignment
var i = 0;
var a = [];
while (i < 100000) {
  a[i] = "Some short unique string " + i;
  i++;
}
ready
Fixed array
var i = 0;
var a = new Array(100000);
while (i < 100000) {
  a[i] = "Some short unique string " + i;
  i++;
}
ready
Direct with length
var i = 0;
var a = [];
while (i < 100000) {
  a[a.length] = "Some short unique string " + i;
  i++;
}
ready

Revisions

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