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

Revision 26 of this benchmark created on


Description

Angular 1.0.7 stable 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() {
      sum += 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];
  sum += 1;
};
ready
coffee for loop
for (i = _i = 0, _len = arr.length; _i < _len; i = ++_i) {
  item = arr[i];
  sum += 1;
}
ready

Revisions

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