splice vs slice when removing element (v8)

Revision 8 of this benchmark created on


Description

Check what's better to remove an element from an array

Preparation HTML

<script>
 
  var a = [], i = 1000;
  while (i > 0) {
    a.push({v:Math.random(), v1:i})
    i--;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
slice
var sliced = a.slice(0, 500).concat(a.slice(501))
ready
splice
var spliced = a.splice(500, 1);
ready
splice + cloned array
b = a.slice();
b.splice(500, 1);
var spliced = b;
ready

Revisions

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