jQuery.each vs. for loop (v110)

Revision 110 of this benchmark created on


Preparation HTML

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

  function fx(a) {
    e = a;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
// async test
$.each(a, function() {
  e = this;
});
ready
for loop
// async test
for (var i = 0, len = a.length; i < len; i++) {
  e = a[i];
};
ready
while loop
var i = a.length - 1;

while (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
for with fn
for (var i = 0, len = a.length; i < len; i++) {
  fx(a[i]);
};
ready

Revisions

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