array vs object member access

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [],
        b = {};
    a.INDEX = 90123123;
    INDEX = 1203809123;
};
</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
a[0] = 1;
a[1] = 2;
a[2] = 4;
pending…
object
b.a = 1;
b.b = 2;
b.c = 4;
pending…
object2
b['a'] = 1;
b['b'] = 2;
b['c'] = 4;
pending…
member constant
a[a.INDEX] = 5
a[a.INDEX] = 6
a[a.INDEX] = 7
pending…
direct constant
a[INDEX] = 5
a[INDEX] = 6
a[INDEX] = 7
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