jQuery vs Underscore Each

JavaScript performance comparison

Revision 5 of this test case created

Info

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

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://github.com/documentcloud/underscore/blob/master/underscore-min.js"></script>
<script src="//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>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/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);
});
pending…
Underscore.js Each
_(Modernizr).each(function(value, property,object){
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
pending…
jQuery Each Non--OO
$.each(Modernizr, function(property, value) {
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
pending…
Underscore.js Each Non-OO
_.each(Modernizr, function(value, property,object){
        $('<div/>', {
                 id: property
                ,css: {
                        width   : '100%'
                }
                ,html: property + ' ' + value
        }).appendTo($content);
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment