Angular forEach vs. Native for loop (v34)

Revision 34 of this benchmark created on


Preparation HTML

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

Setup

function makeDataset(name) {
      return {
        window: name,
        source: "DX",
        spend: "1642.81",
        ideal_spend: "2989.86",
        pace: "43",
        impressions: "224929",
        actions: "189",
        cpm: "3.90",
        ideal_cpm: "2.81",
        cpa: "25.82"
      };
    }
    
    var stats = [makeDataset("window")];
    for (var i = 0; i < 10000; i++) {
      stats.push(makeDataset(new String(i)));
    }
    
    var w, retObj;
    function processDataset(dataset) {
      w = dataset.window;
      if (w === 'lifetime') {
        delete dataset.window;
        retObj = dataset;
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Angular forEach
angular.forEach(stats, processDataset);
 
ready
Native For
for (var i = stats.length - 1; i >= 0; i--) {
  processDataset(stats[i]);
}
ready
Native forEach
stats.forEach(processDataset);
 
ready

Revisions

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