$each vs _.each vs for in

Benchmark created 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-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) {
  value = jsObject[key];
}
ready

Revisions

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