$each vs _.each vs for in (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//documentcloud.github.com/underscore/underscore-min.js"></script>
<script>
  var jsObject = {
    num: 1,
    bool: 2,
    array: [1, 2, 3]
  },
  
  value;
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
$.each
$.each(jsObject, function(key, val) {
  value = val;
});
ready
_.each
_.each(jsObject, function(val, key) {
  value = val;
});
ready
for in
for(var key in jsObject) {
  if (jsObject.hasOwnProperty(key)) {
    value = jsObject[key];
  }
}
ready

Revisions

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