jQuery each2 plugin vs jQuery core .each method (v32)

Revision 32 of this benchmark created by Yukulélé on


Description

Basically, if you're going to do $(this) inside an .each loop, you should consider using the jQuery each2 plugin instead, because it's specifically optimized for this extremely common use case!

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<!-- the plugin -->
<script src="http://github.com/cowboy/jquery-misc/raw/master/jquery.ba-each2.js"></script>

<script>
  // Create a whole bunch of elements for iteration.
  var elems = $('<div/>').append(Array(1000).join('<span/>')).children();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery each2 plugin
elems.each2(function(i, jq) {
 this; // DOM element
 //jq; // jQuery object
});
ready
jQuery core .each method
elems.each(function(i, elem) {
 this; // DOM element
 //$(this); // jQuery object
});
ready

Revisions

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