jQuery.each vs. for loop (v74)

Revision 74 of this benchmark created on


Preparation HTML

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

function bar(i,item) {
   return a = 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
reverse while
var i = a.length
while (i--) {
  e = a[i];
}
ready
foreach
a.forEach(function( elem ) {
  e = elem;
});
ready
jquery each no nest
$(a).each(bar);
ready
short hand for
for ( ; j < a.length; ) {
  e = a[j];
};
ready
short hand with var
var k = 0;
for ( ; k < a.length; ) {
  e = a[k];
};
ready

Revisions

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