Array Performance

JavaScript performance comparison

Revision 47 of this test case created

Info

Manual array lookups vs. holey arrays.

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var a1 = [];
    var o1 = {};
    for (var i = 0; i < 1000; i++) {
              var id = Math.floor(Math.random() * 100000) + 1;

if(i===500){
a1.push("TEST");
              o1.TEST = "TEST";
}

              a1.push(id);
              o1.id = id;

    }


  };
</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
Manual Array Lookup
var id = "TEST";
for (var i = 0; i < a1.length; i++) {
  if (a1[id] !== undefined) break;
}
 
pending…
indexOf
a1.indexOf("TEST");
pending…
Object by Key
if( o1["TEST"] !== undefined){

}
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