Angular forEach vs. Native for loop (v57)

Revision 57 of this benchmark created by ViBiOh on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>

Setup

var dataset, retObj = undefined, stats = [];
    for (var nb = 0; nb < 1000; ++nb) {
      stats.push({
        id: nb,
        label: 'label_for_' + nb
      });
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Angular forEach
angular.forEach(stats, function(dataset) {
  if (retObj === undefined && dataset.label === 'label_for_888') {
    retObj = dataset;
  }
});
ready
Native For
var i = 0;
for (var j = stats.length; i < j && stats[i].label !== 'label_for_888'; ++i);
retObj = stats[i];
ready
Native forEach
stats.forEach(function(dataset) {
  if (retObj === undefined && dataset.label === 'label_for_888') {
    retObj = dataset;
  }
})
ready
Some
stats.some(function(dataset) {
  if (dataset.label === 'label_for_888') {
    retObj = dataset;
    return true;
  }
  return false;
});
ready

Revisions

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