jQuery.each vs _.each vs for loop

JavaScript performance comparison

Revision 39 of this test case created by Andrew

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
  var lodash = _.noConflict();
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var $ = window.$;
  var _ = window._;
  var lodash = window.lodash;
  
  var e;
  // var array = ['test', 12, 1, 'aasdf', 'a', 'abc', 'new', 1,2,3,3,4,4,3,2];
  var array = $('a');

};
</script>

Preparation code output

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> <script> var lodash = _.noConflict(); </script>

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
jQuery.each
$.each(array, function(index, element) { e = element; })
pending…
_.each (underscore)
_.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.

0 Comments