Splicing a single value (v27)

Revision 27 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.unshift('foo');
ready

Revisions

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