Splicing a single value (v48)

Revision 48 of this benchmark created on


Setup

var arr = new Array();
    for (var i = 0; i < 10000; i++) {
     arr.push({ b: i });
    };
    for (var i = 65000; i < 70000; i++) {
     arr[i] = { h: 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.push('foo');
ready
remove
arr.splice(half, 1);
ready
slice
arr.slice(0, half).concat(arr.slice(half + 1))
ready

Revisions

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