Splicing a single value (v39)

Revision 39 of this benchmark created on


Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
Splice insertion at half-way point
arr.splice(half, 0, 'foo');
ready
Splice insertion at a random point
arr.splice(randomInt(arr.length), 0, 'foo');
ready
Push
arr.push('foo');
ready
Shift
arr.shift('foo');
ready
Direct Removal
var last = arr.length - 1;
arr[0] = arr[last];
arr[last] = void 0;
arr.length = last;
ready

Revisions

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