Angular foreach vs Underscore foreach vs native For Loop vs reverse native for loop

JavaScript performance comparison

Revision 10 of this test case created by

Preparation code

 <script src=""></script>

 <script src=""></script>
 <script src=""></script>

Benchmark.prototype.setup = function() {
  (function($) {
    // Create a placeholder jQuery object with a length of 1. The single item
    // is completely arbitrary and will be replaced.
    var jq = $([1]);
    $.fn.each2 = function( fn ) {
      var i = -1;
      while (
        // Set both the first element AND context property of the placeholder
        // jQuery object to the DOM element. When i has been incremented past the
        // end, this[++i] will return undefined and abort the while loop.
        ( jq.context = jq[0] = this[++i] )
        // Invoke the callback function in the context of the DOM element,
        // passing both the index and the placeholder jQuery object in. Like
        // .each, if the callback returns `false`, abort the while loop.
        && jq[0], i, jq ) !== false
      ) {}
      // Return the initial jQuery object for chainability.
      return this;
  var sum = 0;
  var arr = [];
  var myFunc = function() {
    sum += 1;
  for (var i = 0; i < 100000; i++) {


Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
angular foreach
angular.forEach(arr, myFunc);
underscore foreach
_.each(arr, myFunc);
for loop
for (var i = 0; i < arr.length; i++) {
  sum += 1;
for loop reverse
for (var i = arr.length - 1; i >= 0; i--) {
  sum += 1;
for loop with caching
for (var i = 0, len = arr.length; i < len; i++) {
  sum += 1;
browser forEach
jQuery .each
$.each(arr, myFunc);
$.each2(arr, myFunc);
native for with caching and revered
for (var i = arr.length; i--;) {
  sum += 1;

Compare results of other browsers


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


Andrei commented :

It would be great to see Lo-Dash thrown in the mix

polo2016 commented :

roshe run, juicy couture clothings, michael kors outlet online, iphone 5 cases, oakley outlet, hogan, ray ban sunglasses, michael kors outlet, kanye west shoes, salvatore ferragamo, nfl rams, replica watches, coach outlet, skechers, nfl ravens, tory burch sale, michael kors outlet online sale, jerseys from china, levis outlet store, tommy hilfiger, bcbg max azria, cheap oakley sunglasses, prada handbags, nba jerseys, coach outlet online, thomas sabo uk, michael kors bags, shop coach factory, fred perry shoes, coach bags, polo ralph, valentino shoes outlet, salomon schuhe, shoes on sale,, nfl 49ers, ray bans, nike online, prada sunglasses, scarpe hogan, kobe bryant jersey, coach factory outlet online, nfl jaguars, new balance shoes, red bottoms, swarovski, michael kors australia, nfl panthers, oakley sunglasses, air jordan shoes, nike outlet store, lunette oakley pas cher, rolex, coach outlet en ligne , timberland boots, nfl buccaneers, cheap basketball shoes, hollister co, lunette ray ban pas cher, coach factory outlet online, charlotte hornets jersey, roshe run, mia jersey, portland trail blazers, chi hair,, ralph lauren online, longchamp taschen, adidas sneakers, true religion, nfl bills, adidas shoes outlet, true religion jeans women, mcm handbags, north face jackets, polo outlet online, ecco women shoes, michael kors outlet online, free running, kate spade outlet online, cheap glasses, pandora, uhren, cheap eyeglasses, supra footwear, nike mercurial, uggs, cheap nike shoes, cheap ray ban, designer handbags, designer handbags, nfl bears, barbour mens jackets, nike huaraches, the north face, skechers womens shoes, nfl redskins, nop jerseys, hermes outlet, ray ban sbocco, mizuno running shoes,, dsquared2 jeans, toms outlet, chicago bulls, coach outlet online, bottega, nike mercurial vapor, converse shoes, denver nuggets , swarovski, burberry, polo ralph lauren outlet online, nfl browns, nfl colts, toms shoes, links of london bracelets, ray ban sunglasses outlet, under armour curry, womens hoodies, ray ban sunglasses, guciheaven, barbour women jackets, ray ban wayfarer, minnesota timberwolves, cheap jerseys, nfl seahawks, fendi outlet online, swarovski, birkenstock outlet, coach outlet, fake rolex, cheap jerseys, jimmy choo, moncler outlet online, louboutin shoes, knicks jerseys, ralph lauren shirts, air max 2014, hermes birkin, nba jerseys outlet, prada outlet, air max 95, philadelphia 76ers jersey, jimmy choo shoes, coach outlet sale, timberland homme, michael kors purses, jerseys from china, coach factory outlet online, longchamp, cheap michael kors, pistons jersey, hollister kids, rayban, omega watches, roshes, ed hardy clothing, louboutin, san antonio spurs, ray ban outlet, versace shoes outlet, hermes bags, nba jerseys, ferragamo outlet, christian louboutin shoes, ralph lauren factory store, birkenstock taschen deutschland, polo ralph lauren, ralph lauren polo, milwaukee bucks, polo ralph lauren, giuseppe shoes, ray ban outlet, lacoste shirts, vans outlet, ralph lauren, toms shoes outlet, polo ralph lauren outlet, kevin durant shoes, soccer outlet online, ralph lauren uk, belstaff sale, fidget spinner, swarovski jewelry, woolrich outlet online, plein outlet, michael kors bags, bottega veneta, kate spade outlet, guess bags outlet,, longchamp,, suns jerseys, cheap oakley sunglasses, ferragamo shoes, christian louboutin, hollister clothing store, bos jersey, asics, nike air max, louboutin outlet, softball bats, relojes especiales, jack wolfskin, burberry handbags, michael kors canada, pandora bracelets, replica rolex, coach factory online, timberland shoes, nfl steelers, michael kors, vibram shoes, ralph lauren, toronto raptors, nfl raiders, nike air max 2015, nfl patriots, tommy hilfiger online shop, ralph lauren outlet, salvatore ferragamo,, michael kors, nike max, utah jazz, fitflop , converse chucks, ugg australia, true religion jeans outlet, burberry outlet, versace outlet, reebok shoes, gucci womens shoes, ray ban, nike air, nfl chiefs, vans schuhe, the north face, coach outlet, ralph lauren tracksuits, chrome hearts jewelry, burberry, nike outlet, burberry outlet online, polo ralph lauren, calvin klein, michael kors bags, nfl titans, cleveland cavaliers jerseys, nfl lions, toms shoes, new balance, ralph lauren outlet online, vans shoes, nets jersey, thomas sabo, nfl jets, michael kors outlet online sale, nike free shoes, true religion outlet, replica watches, gucci mens shoes, converse, air jordan retro, cheap oakley, nike air force, memphis grizzlies, c&c beanies wholesale, ray ban sunglasses, longchamp handbags, north face, air max, armani clothing, guess jeans, prada, roche run, ray ban, nba jerseys, oakley, long champ, indiana pacers, northface, hollister, converse outlet, puma outlet store, toms outlet, cheap jerseys, moncler women jackets, cheap oakley sunglasses, toms outlet, new balance, baseball jerseys, air jordans, nfl azcardinals, the north face outlet, ferragamo, polo ralph lauren outlet, parajumpers outlet online, pandora, baseball bats, burberry sale, adidas, flat iron, cheap michael kors, nike tn requin, adidas superstar, burberry handbags, nfl saints, cheap true religion, mcm bags, hogan shoes outlet, nike air max, coach outlet, skechers, nike free 5.0, cheap oakley, huaraches, north face outlet, oakley outlet online, orlando magic, mizuno running, replica handbags, hollister, katespade outlet, michael kors handbags, replica watches, nike store, coach black friday, nfl eagles, Hermes, nfl giants, michael kors v?skor, cheap true religion, kate spade, jack wolfskin outlet online, houston rockets, longchamp outlet, mont blanc pens,, nike roshe, montre pas cher, tommy hilfiger, bcbg dresses, nike air max, rolex replica, michael kors, pandora rings, new balance, oakley prescription, free run, nfl falcons, ralph lauren, oakley sunglasses outlet, tommy hilfiger outlet stores, nike air max, belstaff mens jackets, stone island store, nike roshe, fred perry,, burberry handbags, iphone 4s cases, jordan release dates, under armour ua shoes, tory burch shoes, north face backpacks, timberland outlet, marc jacobs outlet, celine handbags, ralph lauren, russell westbrook jersey, jerseys from china, coach purses, supra shoes, nfl dolphins, reebok, cheap jerseys, swarovski australia, nfl vikings, pandora rings, nfl bengals, oakley sunglasses, rayban, asics, pandora, watches,, adidas neo, lacoste polos, givenchy bags outlet, louboutin, mcm backpack outlet, hugo boss outlet, nike air max 2014, juicy couture, pandora jewellery, babyliss, jordan shoes, philipp plein clothes, abercrombie, hollister online shop deutschland, hilfiger outlet, dallas mavericks jersey, michael kors purses, nike air force, swarovski crystal, longchamp outlet, barbour outlet, nike free run, nba jerseys outlet, air max, mbt shoes outlet, air jordan, nike huarache, michael kors, burberry outlet online, gsw jerseys, nike air, the north face, soccer shoes, michael kors purses, barbour mens jackets, giuseppe zanotti, dansko shoes, ray ban sunglasses, mcm bags, burberry online shop, air max 90, hilfiger, jordans for sale, asics gel, nfl jerseys, coach factory outlet online, ralph lauren outlet, adidas shoes, washington wizards, new balance store, gafas oakley, air max shoes, occhiali oakley, oakley sunglasses cheap, nfl cowboys, zapatillas nike, prada outlet, ralph lauren uk, christian louboutin, marc jacobs handbags, north face pas cher, barbour women jackets, dsquared2 shoes, nfl packers, nfl broncos, nfl texans, mont blanc, tods mens shoes, birkenstock taschen outlet, burberry handbags, wholesale handbags, puma, michael kors outlet online, mcm outlet, ray ban zonnebril, rayban sunglasses, belstaff, oakley, nfl chargers, thomas sabo, sac jerseys, los angeles clippers, oakley sunglasses outlet, burberry outlet online, burberry uk