for loops (v3)

Revision 3 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
jquery
$.each(a, function() {
  e = this;
});
ready
for-loop (caching)
for (var i = 0, len = a.length; i < len; i++) {
  e = a[i];
};
ready
for-loop (no caching)
for (var i = 0; i < a.length; i++) {
  e = a[i];
};
ready
alternate for loop
for (var i in a) {
  e = a[i];
};
ready
reverse
for (var i = a.length; i--;) {
  e = a[i]
}
ready
native forEach
a.forEach(function(item) {
  e = item;
})
ready
Underscore
_.each(a, function(i, item) {
  e = item;
});
ready
while
while (a.length) {
  e = a.shift();
}
ready

Revisions

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