Array unshift vs prepend (v12)

Revision 12 of this benchmark created by Robin Cloutman 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[i+1]=(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
Splice
a = [1, 2, 3, 4];
a.splice(0, 0, 0);
ready
Concat
a = [1, 2, 3, 4];
[0].concat(a);
ready

Revisions

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