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

Revision 15 of this benchmark created by Yury Molchan on


Test runner

Ready to run.

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