underscore each vs for vs for in loops (v12)

Revision 12 of this benchmark created by test on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://documentcloud.github.com/underscore/underscore.js"></script>
<div id="output"></div>

Setup

var $ = window.jQuery,
      _ = window._,
      arr = {"test" : 123, "best" : 123, "rest" : 123	},
      arr2 = {"test" : 1234, "best" : 1234, "rest" : 1234	},
      obj = {0 : arr, 1 : arr2},
      i,j,
      len = Object.keys(obj).length,
      outputDiv = document.getElementById("output");

Test runner

Ready to run.

Testing in
TestOps/sec
Current Implementation
_.each(obj, function(o, a){
 var a = o.test,
     b = o.best,
     c = o.rest;
outputDiv.innerHTML = "o:" + o + " - a:"+ a + "\n";
});
ready
for loop
for(i= 0; i < len;i++){
 var a = obj[i].test,
     b = obj[i].best,
     c = obj[i].rest;
};
ready
for in loop
for(j in obj){
 var a = obj[j].test,
     b = obj[j].best,
     c = obj[j].rest;
};
ready

Revisions

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

  • Revision 1: published by Jeremy Ashkenas on
  • Revision 4: published by Paul Miller on
  • Revision 5: published by John-David Dalton on
  • Revision 7: published by Shane O'Sullivan on
  • Revision 9: published on
  • Revision 10: published on
  • Revision 11: published by Jesús Germade on
  • Revision 12: published by test on
  • Revision 13: published by Dan on
  • Revision 14: published by Jesús Germade on
  • Revision 15: published by Jesús Germade on
  • Revision 16: published by Jesús Germade on
  • Revision 17: published by mingc on
  • Revision 18: published by Eldar Abusalimov on