Splice vs new

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var tab = new Array(1000);
};
</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 1
for (var i = 0; i < tab.length; i++) {
        if (i == 247) {
                tab.splice(i--, 1);
        }
}
 
pending…
new 1/2
var newTab = [];

for (var i = 0; i < tab.length; i++) {
        if (i != 247) {
                newTab.push(tab[i]);
        }
}


tab = newTab;
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