Splicing a single value (v50)

Revision 50 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() {
   return Math.floor(Math.random() * (arr.length + 1));
  };

  function removeAt(self, from, to) {

            var rest = Array.prototype.slice.call(self, (to || from) + 1 || self.length);

            self.length = from < 0 ? self.length + from : from;
            Array.prototype.push.apply(self, rest);
        };

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Splice insertion at half-way point
getArr().splice(half, 0, 'foo');
ready
Push
getArr().push('foo');
ready
Shift
getArr().shift('foo');
ready
removeAt
removeAt(getArr(), randomInt());
ready
splice random
getArr().splice(randomInt(), 1);
ready

Revisions

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