Angular forEach performance (v12)

Revision 12 of this benchmark created on


Description

Testing Angular forEach vs for in vs for loop over the object's keys

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js">
</script>
<script>
  var arr = new Array(10000);
  var obj = {};
  arr.forEach(function(item) {
    obj['' + item] = item;
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Native forEach
Object.keys(obj).forEach(function(item) {});
ready
Angular forEach
angular.forEach(obj, function(item) {});
ready
Native For..In
for (var key in obj) {
  if(obj.hasOwnProperty(key)){
    obj[key];
  }
}
ready
Native For
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
  obj[keys[i]];
}
ready

Revisions

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