Array Performance (v154)

Revision 154 of this benchmark created on


Description

Manual array lookups vs. holey arrays.

Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>

Setup

var a1 = [];
    for(var i = 0 ; i < 5000 ; i++)
    {
        a1[i] = {id: i, name: 'name1'};
    }


    var a2 = new Array(5000);
    a2[2993] = {id: 2993, name: 'name1'};
    a2[3299] = {id: 3299, name: 'name1'};

    var o = {};
    o['2993'] = {id: 2993, name: 'name1'};
    o['3299'] = {id: 3299, name: 'name1'};

Test runner

Ready to run.

Testing in
TestOps/sec
Manual Array Lookup
var id = '3299';
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id === id) {
    result = a1[i];
    break;
  }
}
ready
Holey Array by Index
var id = '3299';
var result = a2[id];
ready
Object by Key
var id = '3299';
var result = o[id];
ready

Revisions

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