array item removal

JavaScript performance comparison

Test case created by MONTILLET Xavier

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var ARRAY = [ ];
    for ( var i = 0; i <= 999; ++i ) {
        ARRAY[ i ] = i;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
splice - keep all
var array = ARRAY.slice( );
var i = array.length;
while ( i --> 0 ) {
    if ( ! array[ i ] ) {
        array.splice( i, 1 );
    }
}
pending…
splice - keep half
var array = ARRAY.slice( );
var i = array.length;
while ( i --> 0 ) {
    if ( array[ i ] % 2 ) {
        array.splice( i, 1 );
    }
}
pending…
splice - keep none
var array = ARRAY.slice( );
var i = array.length;
while ( i --> 0 ) {
    if ( array[ i ] ) {
        array.splice( i, 1 );
    }
}
pending…
filter - keep all
var array = ARRAY.slice( );
array = array.filter( function ( item ) {
    return item;
} );
pending…
filter - keep half
var array = ARRAY.slice( );
array = array.filter( function ( item ) {
    return item % 2;
} );
pending…
filter - keep none
var array = ARRAY.slice( );
array = array.filter( function ( item ) {
    return !item;
} );
pending…

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

Compare results of other browsers

0 comments

Add a comment