jQuery.each vs. alternatives (v49)

Revision 49 of this benchmark created on


Description

Each comparisons

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var b = $('*'), a = b.get(),
      e;

  jQuery.fn.quickEach = (function() {
   var jq = jQuery([1]);
   return function(c) {
    var i = -1,
        el, len = this.length;
    try {
     while (++i < len && (el = jq[0] = this[i]) && c.call(jq, i, el) !== false);
    } catch (e) {
     delete jq[0];
     throw e;
    }
    delete jq[0];
    return this;
   };
  }());
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each with KeyVal
$.each(a, function(key, val) {
 e = val;
});
ready
for loop
var len = a.length;
for (var i = 0; i < len; i++) {
 e = $(a[i]);
};
ready
alternative for loop
for (var i in a) {
 e = $(a[i]);
};
ready
jQuery.fn.each
b.each(function(i){
 e = $(this);
});
ready
jQuery.fn.quickEach()
b.quickEach(function(i){
 e = this;
});
ready

Revisions

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