Angular forEach, Native for loop, Native while loop, Lo-Dash (v45)

Revision 45 of this benchmark created by mvcninja on


Description

_.foreach uses while loop, angular.forEach uses native forEach iterator if possible, otherwise uses for loop

Preparation HTML

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>

Setup

var dataset, i, retObj = {}, stats = [{
        "window": "lifetime",
        "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"
      }, {
        "window": "yesterday",
        "source": "DX",
        "spend": "1634.57",
        "ideal_spend": "3276.75",
        "pace": "24",
        "impressions": "24771",
        "actions": "41",
        "cpm": "2.08",
        "ideal_cpm": "3.14",
        "cpa": "16.00"
      }];
    
    for (var i=0; i<500; i++) { 
      stats.push(stats[0]);
    }
    
    var callback = function(dataset, key){
      if (dataset.window && dataset.window === 'lifetime') {
        delete dataset.window;
        retObj = dataset;
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Angular forEach
angular.forEach(stats, callback);
ready
Native For
for (var i = 0; i < stats.length; i++) {
  callback.call(this, stats[i], i);
}
ready
Native While
var i = -1;
while (++i < stats.length) {
  callback.call(this, stats[i], i);
}
ready
Lo-Dash _.each
_.each(stats, callback, this);
ready

Revisions

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