arrays vs objects wrt referencing properties / indicies

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var length = 1000000;
    var obj = {};
    var ra = [];
   
    for (var i = 0; i < 1000000; i++) {
    obj[i] = obj;
    ra[i] = obj;
    }
};

Benchmark.prototype.teardown = function() {
    ra.length = 0;
};
</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
objs
for (i = 0; i < length; i++) {
obj[i];
}
pending…
arrays
for (i = 0; i < length; i++) {
ra[i];
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment