Splicing a single value (v25)

Revision 25 of this benchmark created on


Preparation HTML

<script>
  var arr = [];
  for (var i = 0; i < 10000; i++) {
   arr.push(i);
  };
  var half = Math.floor(arr.length / 2);
  
  function getArr() {
   return arr.slice(0);
  };
  
  function randomInt(max) {
   return Math.floor(Math.random() * (max + 1));
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Splice insertion at half-way point
getArr().splice(half, 0, 42);
ready
Push
getArr().push(42);
ready
Unshift
getArr().unshift(42);
ready
Splice at beginning of array
getArr().splice(0, 0, 42);
ready

Revisions

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