Array vs Object Access

JavaScript performance comparison

Revision 7 of this test case created

Info

JavaScript arrays are basically just objects with integer property names. Is there any performance difference when accessing an array vs an object?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    a= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    o= {"a":1, "b":2, "c":3, "d":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10};
   
};
</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 access
a[3];
a[4];
a[6];
a[9];
pending…
Object access
o.a;
o.b;
o.c;
o.d;
pending…
Object access 2
o["a"];
o["b"];
o["c"];
o["d"];
pending…
Object access Numbers
o["5"];
o["6"];
o["7"];
o["8"];
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