jQuery vs Underscore Each (v2)

Revision 2 of this benchmark created on


Description

Is jQuery's $.each or Underscore's _.each faster?

Preparation HTML

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

<div id="testContainer" style="display:none;">
    <div id="content"></div>
</div>
<script>
  var $content = $('#content');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Each
// I couldn't delete this test, so now it's the same as #3
$.each(Modernizr, function(property, value) {
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
ready
Underscore.js Each
_(Modernizr).each(function(value, property,object){
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
ready
jQuery Each Non--OO
$.each(Modernizr, function(property, value) {
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
ready
Underscore.js Each Non-OO
_.each(Modernizr, function(value, property,object){
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
ready

Revisions

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