Angular foreach vs Underscore foreach vs native For Loop vs reverse native for loop (v30)

Revision 30 of this benchmark created by Luscus on


Description

Angular 1.3.0 forEach vs Underscore.js each

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>

Setup

var sum = 0;
    var arr = [];
    var myFunc = function(el) {
      el += 1;
    }
    for (var i = 0; i < 100000; i++) {
      arr.push(i)
    }

Test runner

Ready to run.

Testing in
TestOps/sec
angular foreach
angular.forEach(arr, myFunc);
ready
underscore foreach
_.each(arr, myFunc);
ready
for loop
for (var i = 0; i < arr.length; i++) {
item = arr[i];
  item += 1;
};
ready
while/reverse
var i = arr.length;
arr.reverse();

while (i--) {
item = arr[i];
  item += 1;
};
ready

Revisions

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