unshift() vs push()+reverse() (v2)

Revision 2 of this benchmark created on


Setup

var test = [],
      i = 20000;
    while (i--) test.push("foo" + i);

Test runner

Ready to run.

Testing in
TestOps/sec
unshift
var arr = [],
  i = 20000;
while (i--) arr.unshift("foo" + i);
ready
push
var arr = [],
  i = 20000;
while (i--) {
  arr.push("foo" + i)

};
arr = arr.reverse();
ready
push no reverse
var arr = [],
  i = 20000;
while (i--) arr.push("foo" + i);
ready
var
i = 20000;
while (i--) {
  test.pop()

};
ready
var tmp,
  i = 20000;
while (i--) {
  tmp = new Array(20000);

};
ready
var tmp,
  i = 20000;
while (i--) {
  tmp = [];
  tmp.length = 20000;
};
ready
var tmp,
  i = 20000;
while (i--) {
  tmp = [];
};
ready

Revisions

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