Speed test: while() cycle vs. jQuery's each() function
<p>I have an array of objects called <code>targets</code> and I want to execute a function on each of those objects. The first method:</p>

<pre><code>targets.each(function() {
    if (needScrollbars($(this))) {
        wrap($(this), id);
        id = id + 1;
    }
});
</code></pre>

<p>This method gives execution speed of ~125ms. The second method is:</p>

<pre><code>var i=0;
while (targets[i] != undefined) {
    if (needScrollbars($(this))) {
        wrap($(this), id);
        id = id + 1;
    }
    i = i+1;
}
</code></pre>

<p>This second method takes whopping 1385ms to execute and I get my head around that. Does anyone have any idea why a bare bones cycle runs slower than a function which I'm only guessing that's doing (just guessing) a whole lot more than a simple cycle?</p>

<p>Thank you.</p>
