Array Performance

JavaScript performance comparison

Revision 74 of this test case created by

Preparation code

<script src="https://raw.githubusercontent.com/lodash/lodash/2.4.1/dist/lodash.js"></script>
<script>
  Benchmark.prototype.setup = function() {
    var a1 = [{id: '29938', name: 'name1'}, {id: '32994', name: 'name1'}];

    var a2 = [];
    a2[29938] = {id: 29938, name: 'name1'};
    a2[32994] = {id: 32994, name: 'name1'};

    var o = {};
    o['29938'] = {id: '29938', name: 'name1'};
    o['32994'] = {id: '32994', name: 'name1'};
  };
var id = '29938';
function func(val, i){
 //  if (val.id === id) 
  // result = val;
}
</script>
    

Preparation code output

<script> Benchmark.prototype.setup = function() { var a1 = [{id: '29938', name: 'name1'}, {id: '32994', name: 'name1'}]; var a2 = []; a2[29938] = {id: 29938, name: 'name1'}; a2[32994] = {id: 32994, name: 'name1'}; var o = {}; o['29938'] = {id: '29938', name: 'name1'}; o['32994'] = {id: '32994', name: 'name1'}; }; var id = '29938'; function func(val, i){ // if (val.id === id) // result = val; } </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
Manual Array Lookup
for (var i = 0; i < a1.length; i++) {
  func(a1[i]);
}
pending…
lodash
_.each(a1, function(val, i, arr) {
   func(val)
});
pending…
var id = '29938';
var result = o[id];
pending…
Native ForEach
a1.forEach(function(val) {
   func(val)
});
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