Object delete vs. array splice vs. array delete

JavaScript performance comparison

Revision 3 of this test case created by Quentin Brooks

Preparation code

<script>
  var count = 100000;
  var deleteInc = 100;
</script>
      
<script>
Benchmark.prototype.setup = function() {
    var someArr = [];
    var someObj = {};
    for(var i = 0; i < count; i++)
    {
      someArr[i] = Math.floor(Math.random() * 1000000);
      someObj['a' + i] = Math.floor(Math.random() * 1000000);
    }
  

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Splice
for(var i = 0; i < count; i += deleteInc)
{
    someArr.splice(i, 1);
}
pending…
Object Delete
for(var i = 0; i < count; i += deleteInc)
{
    delete someObj['a' + i];
}
pending…
Array Delete
for(var i = 0; i < count; i += deleteInc)
{
    delete someArr[i];
}
pending…
Object sub-script Delete
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.

0 Comments