Array Performance

JavaScript performance comparison

Revision 139 of this test case created by Jonatas Miguel

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var aI = 29938;
    var a = [];
    a[29938] = {id: 29938, name: 'name1'};
    a[32994] = {id: 32994, name: 'name2'};

    var oI = '29938';
    var o = {};
    o['29938'] = {id: 29938, name: 'name1'};
    o['32994'] = {id: 32994, name: 'name2'};

    var o2 = {};
    o2['_29938'] = {id: 29938, name: 'name1'};
    o2['_32994'] = {id: 32994, name: 'name2'};

    var o3 = {};
    for(var i = 29938; i <= 32994; i += 3056){
        o3['_' + i] = { id: i, name: 'name' + i };
    }
  };
</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
Holey Array by Index
var result = a[29938];
pending…
Object by Key
var result = o['29938'];
pending…
Object by Property
var result = o2._29938;
pending…
Object by Property
var result = o3._29938;
pending…
simple assignment
var result = aI;
pending…
Just get aI
aI
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.

1 Comment

Jonatas Miguel (revision owner) commented :

I added the last two benchmarks on purpose to show that the benchmark might be giving misleading results...

I think this video explains what might be going on here with the dot notation: https://www.youtube.com/watch?v=65-RbBwZQdU

The tl;dw version is: dead code elimination might be happening for the dot notation cases...

Though, that still doesn't explain the discrepancy between the dot notation and the bracket notation... Dead code elimination should be happening there as well, given that they both "do the same thing".