jQuery each2 plugin vs .each$ plugin vs jQuery core .each method

JavaScript performance comparison

Revision 16 of this test case created by Jason DiMeo

Preparation code

<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>
jQuery.fn.extend({
  each$: function(fn) {
    var $elem = jQuery([1]);
    try {
      for (var i = 0; i < this.length; i++) {
        if (fn.call(jQuery.context = $elem[0] = this[i], i, $elem) === false) { break; }
      }
    } finally {
      delete $elem[0];
    }
    return this;
  }
});
  // Create a whole bunch of elements for iteration.
  var elems = $('<div/>').append(Array(1000).join('<span/>')).children();
</script>
    

Preparation code output

<!-- the plugin --> <script src="http://github.com/cowboy/jquery-misc/raw/master/jquery.ba-each2.js"></script> <script> jQuery.fn.extend({ each$: function(fn) { var $elem = jQuery([1]); try { for (var i = 0; i < this.length; i++) { if (fn.call(jQuery.context = $elem[0] = this[i], i, $elem) === false) { break; } } } finally { delete $elem[0]; } return this; } }); // Create a whole bunch of elements for iteration. var elems = $('<div/>').append(Array(1000).join('<span/>')).children(); </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 each2 plugin
elems.each2(function(i, jq) {
 this; // DOM element
 jq; // jQuery object
});
pending…
jQuery core .each method
elems.each(function(i, elem) {
 this; // DOM element
 $(this); // jQuery object
});
pending…
jQuery each$ plugin
elems.each$(function(i, $elem) {
 this; // DOM element
 $elem; // jQuery object
});
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