for loop vs $.each (v14)

Revision 14 of this benchmark created on


Description

<div id="id_1"> <span>foo0</span> <span>foo1</span> <span>foo2</span> <span>foo3</span> <span>foo4</span> <span>foo5</span> <span>foo6</span> <span>foo7</span> <span>foo8</span> </div>

Preparation HTML

<div id="id_1">
  <span>
    foo0
  </span>
  <span>
    foo1
  </span>
  <span>
    foo2
  </span>
  <span>
    foo3
  </span>
  <span>
    foo4
  </span>
  <span>
    foo5
  </span>
  <span>
    foo6
  </span>
  <span>
    foo7
  </span>
  <span>
    foo8
  </span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var $set = jQuery('#id_1').children();

  function myeach(arr, func) {
    for (var i = 0; i < arr.length; i++) {
      func(i, arr[i]);
    }
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var i = 0, len = $set.length; i < len; i++) { b = $set[i];}
ready
$.each
$set.each(function(i, e) {b = $set[i];});
ready
my each
myeach($set, function(i, l) {b = $set[i];});
ready
reverse for
for (var i = $set.length; i > 0; i--) {b = $set[i];}
ready

Revisions

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