Object delete vs. array splice vs. array delete

JavaScript performance comparison

Revision 9 of this test case created

Info

Is it faster to remove an item from an array (and thus allow the indices to be renumbered) or delete a property from an object. Also, checking deletion from array, but this does not renumber the indices so may not be preferable.

Edit: Changed array and object setup to setup code so that it's accurately tested, increased array and object size to see if any difference to array reordering (splice is faster on older test for me for some reason)

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var someArr = [];
    var someObj = {};
    for (var i = 0; i < 1024; i ++) {
        someArr[i] = i;
        someObj[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
Array Splice
someArr.splice(50, 1);
pending…
Object Delete
delete someObj[50];
pending…
Array Delete
delete someArr[50];
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment