Array unshift vs prepend (v18)

Revision 18 of this benchmark created on


Preparation HTML

<script>
  var a;
  var prependArray = function(value, oldArray) {
   var i, len = oldArray.length + 1,
       newArray = new Array(len);
   newArray[0] = value;
   for (i = 0; i < len; ++i) {
    newArray.push(oldArray[i]);
   }
   return newArray;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Unshift
a = [1, 2, 3, 4];
a.unshift(0);
ready
Prepend function
a = [1, 2, 3, 4];
prependArray(0, a);
ready
Unshift without mutation
a = [1, 2, 3, 4];
a.slice(0).unshift(0);
ready
push
a = [1, 2, 3, 4];
a.push(0);
ready
concat
a = [0]
a.concat([1, 2, 3, 4])
ready

Revisions

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