AngularJS forEach vs Native forEach vs key vs for (v14)

Revision 14 of this benchmark created by Jim Marion on


Description

Compare performance of the following iterative patterns:

AngularJS angular.forEach Native array.forEach Native for key in arr Native for loop

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js">
</script>
<script>
  var len = 1000;
  var arr = new Array();
  while (len--) {
    arr[len] = len;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Native forEach
arr.forEach(function(item) {
  item;
});
ready
AngularJS forEach
angular.forEach(arr, function(item) {
  item;
});
ready
for key in arr
for (var key in arr) {
  arr[key];
}
ready
for loop
for (i = arr.length - 1; i >= 0; i--) {
  arr[i];
}
ready

Revisions

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