jQuery 1.7 each vs native for loop (v6)

Revision 6 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>
<ul>
  <li>
    Item 01
  </li>
  <li>
    Item 02
  </li>
  <li>
    Item 03
  </li>
  <li>
    Item 04
  </li>
  <li>
    Item 05
  </li>
  <li>
    Item 06
  </li>
  <li>
    Item 07
  </li>
  <li>
    Item 08
  </li>
  <li>
    Item 09
  </li>
  <li>
    Item 10
  </li>
  <li>
    Item 11
  </li>
  <li>
    Item 12
  </li>
  <li>
    Item 13
  </li>
  <li>
    Item 14
  </li>
  <li>
    Item 15
  </li>
  <li>
    Item 16
  </li>
  <li>
    Item 17
  </li>
  <li>
    Item 18
  </li>
  <li>
    Item 19
  </li>
  <li>
    Item 20
  </li>
</ul>
<script>
  var $listItems = $('li'),
      $element;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
native for
var length = $listItems.length;
for (var i = 0; i < length; i++) {
  $element = $($listItems[i]);
}
ready
jQuery 1.7 .each()
$listItems.each(function() {
  $element = $(this);
});
ready
jQuery 1.7 $.each()
$.each($listItems, function(index, element) {
  $element = $(element);
});
ready
Reverse native
for (var i = $listItems.length; --i >= 0;) {
  $element = $($listItems[i]);
}
ready

Revisions

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