Each on Array: jQuery vs Underscore vs JS (v2)

Revision 2 of this benchmark created on


Description

Performance of iterating over an array using native JS for loop, jQuery $.each and Underscore _.each

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 array = [1, 2, 3, 4, 5],
      len = array.length,
      i, value;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery $.each (Array)
$.each(array, function(i, val) {
  value = val;
});
ready
Underscore _.each (Array)
_.each(array, function(val) {
  value = val;
});
ready
JS For Loop
i = 0;
for (; i < len; i++) {
  value = array[i];
}
ready
JS forEach
array.forEach(function(val) {
  value = val;
});
ready

Revisions

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