jQuery.each vs _.each vs for loop

JavaScript performance comparison

Revision 9 of this test case created by Wil Neeley

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="//www.boilerjs.com/boiler.js"></script>
<script>
  var boiler = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.0/lodash.min.js"></script>
<script>
  var lodash = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script>
  var array = $('*').get();
  var m = array.length - 1;
</script>
<script>
Benchmark.prototype.setup = function() {
    var $ = window.$;
    var _ = window._;
    var boiler = window.boiler;
    var lodash = window.lodash;
   
    var e;
    var array = window.array;
};
</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
$.each(array, function(index, element) { e = element; })
pending…
_.each (underscore)
_.each(array, function(element) { e = element; });
pending…
_.each (boiler)
boiler.each(array, function(element) { e = element; });
pending…
_.each (lodash)
lodash.each(array, function(element) { e = element; });
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