Removing items from array (v4)

Revision 4 of this benchmark created on


Setup

var a = [], i = 0;
    for (; i < 1000; i++)
        a[i] = Math.floor(Math.random() * 10);

Test runner

Ready to run.

Testing in
TestOps/sec
Array.splice
var b = a.slice();
for (var i = b.length; i--;)
    if (b === 5) b.splice(i, 1);
ready
Parsing array
var b = a.slice();
for (var i = 0, j = 0, l = b.length; i < l; i++)
    if (b !== 5) b[j++] = b[i];
b.length = j;
ready
Parsing array 2.0
var b = a.slice();      
for(var i=0; i<b.length; i++){
                if(b[i] === 5){
                        b[i] = b[b.length - 1];
                        b.length--;
                }
        }
ready

Revisions

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