Browser Diet - jQuery.each vs. for loop (v16)

Revision 16 of this benchmark created on


Preparation HTML

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

 $.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
$.each(a, function() { e = this; })
ready
for loop
for (var i = 0, len = a.length; i < len; i++) { e = a[i]; }
ready
for without caching
for (var i = 0; i < a.length; i++) { e = a[i]; }
ready
alternative for loop
for (var i in a) { e = a[i]; }
ready
reverse for
for (var i = a.length; i--;) { e = a[i]; }
ready
while reverse
var i = a.length;
while(i){ e = a[--i] }
ready
null check
for (var i = 0; e = a[i]; i++) { }
ready
quckEach
$a.quickEach(function() { e = this; })
ready
reverse for loop
for (var i = 0, len = a.length; i = len; i--) { e = a[i]; }
ready

Revisions

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