for loop vs $.each

Benchmark created by Andreas Göbel 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();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var i = 0, len = $set.length; i < len; i++) {}
ready
$.each
$set.each(function(i, e) {});
ready

Revisions

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