Jquery each vs Underscore each vs For loops (v51)

Revision 51 of this benchmark created by long on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>

Setup

var arr = 'disable|customer_group|text|title|link_type|link_page|link_category|link_custom|link_target|description|ID|classes|attr|trigger|hide_text|hide_link|hide_caret|wrap_label|thumb|thumb_image|thumb_image_width|thumb_image_height|thumb_icon|thumb_icon_size|thumb_align|width_by|width_by_columns|column_gutter|width_by_specific|hide_submenu|submenu_type|submenu_mega_align|submenu_flyout_align|submenu_width|submenu_min_width|hide_content|content|color|bgcolor|color_active|bgcolor_active|submenu_bgcolor|hide_mobile|hide_regular|hide_submenu_mobile|hide_submenu_regular'.split('|');
    var e = null;
    
    function Named(o, i) {
      e = o;
    };
    
    function Name2(i, o) {
      e = o;
    };
    
    var forEach = function(a, c) {
      var l = a.length;
      for (var i = 0; i < l; i++) c(a[i], i)
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Jquery each
$.each(arr, function(i, o) {
  e = o;
});
ready
Underscore each
_.each(arr, function(o, i) {
  e = o;
});
ready
For normal
for (var i = 0, len = arr.length; i <= len; i++) {
  e = arr[i];
};
ready
For reversed
for (var l = arr.length; l >= 0; l--) {
  e = arr[l];
};
ready
Native array forEach
arr.forEach(function(o, i) {
  e = o;
});
ready
Native array forEach with Named function
arr.forEach(Named);
ready
custom forEach
forEach(arr, function(o, i) {
  e = o;
});
ready
custom forEach 2
 
ready
custom forEach Named
forEach(arr, Named)
ready
Jquery each Named
$.each(arr, Name2);
ready
Underscore each Named
_.each(arr, Named);
ready
For normal Named
 
ready
custom forEach asm.js Named
 
ready

Revisions

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