Array Performance

JavaScript performance comparison

Revision 153 of this test case created by Andrey

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
  Benchmark.prototype.setup = function() {
    var a1 = [];
    var a2 = [];
    var o = {};

    for(var i=0;i<200;i++){
      var id = (29938+i).toString();
       a1[i] = {id: id , name: 'name1'};
       a2[id]={id: id , name: 'name1'};
       o[id]={id: id , name: 'name1'};
    }
  };
</script>
    

Preparation code output

<script> Benchmark.prototype.setup = function() { var a1 = []; var a2 = []; var o = {}; for(var i=0;i<200;i++){ var id = (29938+i).toString(); a1[i] = {id: id , name: 'name1'}; a2[id]={id: id , name: 'name1'}; o[id]={id: id , name: 'name1'}; } }; </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
lodash
var id = '30000';
var result = _.find(a1, { 'id': id  });
pending…
array->hash
var hash = {};
var id = '30000';
for (var i = 0; i < a1.length; i++) 
{
hash[a1[i].id] = a1[i];
}

var result = hash[id];
pending…
Manual Array Lookup
var id = '30000';
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id === id) result = a1[i];
}
pending…
Holey Array by Index
var id = '30000';
var result = a2[id];
pending…
Object by Key
var id = '30000';
var result = o[id];
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.

0 Comments