jQuery 1.7 each vs native for loop (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>
<script>
  var jq17 = jQuery.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js">
</script>
<script>
  var jq16 = jQuery.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
</script>
<script>
  var jq15 = jQuery.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</script>
<script>
  var jq14 = jQuery.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js">
</script>
<script>
  var jq13 = jQuery.noConflict();
</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 $jq17ListItems = jq17('li'),
      $jq16ListItems = jq16('li'),
      $jq15ListItems = jq15('li'),
      $jq14ListItems = jq14('li'),
      $jq13ListItems = jq13('li');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
native for
var length = $jq17ListItems[length];
for (var i = 0; i < length; i++) {
  console.log("From for: ", $($jq17ListItems[i]));
}
ready
jQuery 1.7 each
$jq17ListItems.each(function() {
  console.log("From each: ", jq17(this));
});
ready
jQuery 1.6 each
$jq16ListItems.each(function() {
  console.log("From each: ", jq16(this));
});
ready
jQuery 1.5 each
$jq15ListItems.each(function() {
  console.log("From each: ", jq15(this));
});
ready
jQuery 1.4 each
$jq14ListItems.each(function() {
  console.log("From each: ", jq14(this));
});
ready
jQuery 1.3 each
$jq13ListItems.each(function() {
  console.log("From each: ", jq13(this));
});
ready

Revisions

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