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

Revision 4 of this benchmark created on


Description

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

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://underscorejs.org/underscore.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.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
AngularJS forEach
angular.forEach(array, function(val) {
  value = val;
});
ready

Revisions

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