Splicing a single value at middle point (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script>
  var arr = [];
  for (var i = 0; i < 50000; 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 end
var arr = getArr();
for (var i = 0; i < 1000; i++) {
  arr.splice(half, 0, -1 - i);
}
ready
Push
var arr = getArr();
for (var i = 0; i < 1000; i++) {
  arr.push(-1 - i);
}
ready
Shift
var arr = getArr();
for (var i = 0; i < 1000; i++) {
  arr.shift(-1 - i);
}
ready

Revisions

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