<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Efficient looping in Javascript</title>
	<atom:link href="http://solutoire.com/2007/02/02/efficient-looping-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/</link>
	<description>Publicing platform</description>
	<lastBuildDate>Thu, 11 Mar 2010 19:44:05 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Solutoire.com &#8250; Javascripts Loop Benchmarks</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-20920</link>
		<dc:creator>Solutoire.com &#8250; Javascripts Loop Benchmarks</dc:creator>
		<pubDate>Tue, 29 Jul 2008 18:04:30 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-20920</guid>
		<description>[...] Possibly related Efficient looping in Javascript &#8594; read this1 year, 5 months ago [...]</description>
		<content:encoded><![CDATA[<p>[...] Possibly related Efficient looping in Javascript &rarr; read this1 year, 5 months ago [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: juraj</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-3173</link>
		<dc:creator>juraj</dc:creator>
		<pubDate>Thu, 24 May 2007 13:09:40 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-3173</guid>
		<description>Hi

nice site thanks for doing the effort, I have a question for anyone I guess, why is the descending loop (the improved) more efficient?

I suspect it is at bit level manipulation, is decrementing a number faster than incrementing it?

bye

j</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>nice site thanks for doing the effort, I have a question for anyone I guess, why is the descending loop (the improved) more efficient?</p>
<p>I suspect it is at bit level manipulation, is decrementing a number faster than incrementing it?</p>
<p>bye</p>
<p>j</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bas</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-977</link>
		<dc:creator>Bas</dc:creator>
		<pubDate>Thu, 29 Mar 2007 16:38:15 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-977</guid>
		<description>When looping over 100 records most tests &#039;ll tell you it took 0ms...</description>
		<content:encoded><![CDATA[<p>When looping over 100 records most tests &#8216;ll tell you it took 0ms&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tc</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-976</link>
		<dc:creator>tc</dc:creator>
		<pubDate>Thu, 29 Mar 2007 16:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-976</guid>
		<description>Well I&#039;ll take this into consideration the next time I&#039;m looping over 100,000 records, but how much of a difference does it make for list of more realistic size.  I mean on the web, I have never really looped over anything more than probably 100 records.  Anyway... still interesting article.</description>
		<content:encoded><![CDATA[<p>Well I&#8217;ll take this into consideration the next time I&#8217;m looping over 100,000 records, but how much of a difference does it make for list of more realistic size.  I mean on the web, I have never really looped over anything more than probably 100 records.  Anyway&#8230; still interesting article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bas</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-972</link>
		<dc:creator>Bas</dc:creator>
		<pubDate>Thu, 29 Mar 2007 14:46:50 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-972</guid>
		<description>I don&#039;t think you read the article very well. It&#039;s not a proof of concept, it&#039;s a comparison between different ways to loop over an Array. You&#039;re right about the optimizations,  but I wanted to show the difference between normal for loops and &#039;improved&#039; loops.
And about the live preview: yeah I know, otherwise this place would be heaven for Mr Evil...</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think you read the article very well. It&#8217;s not a proof of concept, it&#8217;s a comparison between different ways to loop over an Array. You&#8217;re right about the optimizations,  but I wanted to show the difference between normal for loops and &#8216;improved&#8217; loops.<br />
And about the live preview: yeah I know, otherwise this place would be heaven for Mr Evil&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SillyCone</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-895</link>
		<dc:creator>SillyCone</dc:creator>
		<pubDate>Thu, 22 Mar 2007 11:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-895</guid>
		<description>Of course, the while loops can be replaced as easily by an optimized version. It&#039;s just basic algorithmics : as the tests are repeated for every loop, make them as light as you can.
So it would be like :
&lt;code&gt;var max = data.length;
var i = 0;
while (i &lt; max) {
    tmp = data[i++];
}
&lt;/code&gt; 
Djee, your preview box doesn&#039;t work as the posted version... We have to use &#039;&amp; lt ;&#039; instead of &#039;&lt;&#039;.</description>
		<content:encoded><![CDATA[<p>Of course, the while loops can be replaced as easily by an optimized version. It&#8217;s just basic algorithmics : as the tests are repeated for every loop, make them as light as you can.<br />
So it would be like :<br />
<code>var max = data.length;<br />
var i = 0;<br />
while (i &lt; max) {<br />
    tmp = data[i++];<br />
}<br />
</code><br />
Djee, your preview box doesn&#8217;t work as the posted version&#8230; We have to use &#8216;&amp; lt ;&#8217; instead of &#8216;&lt;&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SillyCone</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-884</link>
		<dc:creator>SillyCone</dc:creator>
		<pubDate>Wed, 21 Mar 2007 15:45:47 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-884</guid>
		<description>Sorry about those 2 post trials (can delete them if you wish).

About your 2 native for loops, the second one (reverse iteration) is not an optimization at all, it&#039;s actually the proof of poor algorithm (sorry to be so rude :).
I bet the only thing that slows down the first loop compared to the second is the fact that the second for argument (i &lt; data.length) is run at every cycle of the loop, thus evaluating the length of your array each and everytime.
To &quot;optimize&quot; the first loop, just replace this :
&lt;code&gt;for(var i = 0; i &lt; data.length; i++){tmp = data[i];};&lt;/code&gt;
by this : 
&lt;code&gt;for(var max = data.length, i = 0 ; i &lt; max; i++) { tmp = data[i]; }&lt;/code&gt;
It should do the trick, be as fast as the first one and not reversed. Haven&#039;t tested it though, I must admit (not enough time in a day :)

Apart from that little point, it was a very usefull and instructive test, thanks a lot !</description>
		<content:encoded><![CDATA[<p>Sorry about those 2 post trials (can delete them if you wish).</p>
<p>About your 2 native for loops, the second one (reverse iteration) is not an optimization at all, it&#8217;s actually the proof of poor algorithm (sorry to be so rude :).<br />
I bet the only thing that slows down the first loop compared to the second is the fact that the second for argument (i &lt; data.length) is run at every cycle of the loop, thus evaluating the length of your array each and everytime.<br />
To &#8220;optimize&#8221; the first loop, just replace this :<br />
<code>for(var i = 0; i &lt; data.length; i++){tmp = data[i];};</code><br />
by this :<br />
<code>for(var max = data.length, i = 0 ; i &lt; max; i++) { tmp = data[i]; }</code><br />
It should do the trick, be as fast as the first one and not reversed. Haven&#8217;t tested it though, I must admit (not enough time in a day :)</p>
<p>Apart from that little point, it was a very usefull and instructive test, thanks a lot !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spiros Denaxas</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-808</link>
		<dc:creator>Spiros Denaxas</dc:creator>
		<pubDate>Wed, 14 Mar 2007 17:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-808</guid>
		<description>It is interesting to see that the reverse iteration loop is faster than the normal iteration loop. Out of curiosity, I did the same with Perl:

&lt;code&gt;
idaru:/tmp spiros$ ./loop.pl 
total elements: 500000
Normal loop : 0.269156
Reverse loop : 0.253984
&lt;/code&gt;

500000 elements took 0.26ms to get traversed normally and 0.25ms to get traversed backwards.

The difference seems to get larger as the size of the array grows:
&lt;code&gt;
idaru:/tmp spiros$ ./loop.pl 
total elements: 700000
Normal loop : 0.379325
Reverse loop : 0.353184
&lt;/code&gt;

Spiros</description>
		<content:encoded><![CDATA[<p>It is interesting to see that the reverse iteration loop is faster than the normal iteration loop. Out of curiosity, I did the same with Perl:</p>
<p><code><br />
idaru:/tmp spiros$ ./loop.pl<br />
total elements: 500000<br />
Normal loop : 0.269156<br />
Reverse loop : 0.253984<br />
</code></p>
<p>500000 elements took 0.26ms to get traversed normally and 0.25ms to get traversed backwards.</p>
<p>The difference seems to get larger as the size of the array grows:<br />
<code><br />
idaru:/tmp spiros$ ./loop.pl<br />
total elements: 700000<br />
Normal loop : 0.379325<br />
Reverse loop : 0.353184<br />
</code></p>
<p>Spiros</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stathis</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-807</link>
		<dc:creator>Stathis</dc:creator>
		<pubDate>Wed, 14 Mar 2007 16:46:27 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-807</guid>
		<description>It seems that your blogging software has rendered &quot;i minus minus&quot; as a &quot;i ndash&quot; in your code (an ndash is a slightly longer version of a dash). In my browser it looks like you&#039;re just writing &quot;i minus&quot; which can&#039;t be right. Consider fixing this to avoid confusion :-)</description>
		<content:encoded><![CDATA[<p>It seems that your blogging software has rendered &#8220;i minus minus&#8221; as a &#8220;i ndash&#8221; in your code (an ndash is a slightly longer version of a dash). In my browser it looks like you&#8217;re just writing &#8220;i minus&#8221; which can&#8217;t be right. Consider fixing this to avoid confusion :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Kruse</title>
		<link>http://solutoire.com/2007/02/02/efficient-looping-in-javascript/comment-page-1/#comment-447</link>
		<dc:creator>Matt Kruse</dc:creator>
		<pubDate>Mon, 12 Feb 2007 18:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://solutoire.com/2007/02/02/efficient-looping-in-javascript/#comment-447</guid>
		<description>I did some interesting tests on loop speeds here:
http://www.mattkruse.com/temp/gb_speed.html

The difference is most noticeable in IE. I use the lessons learned in these tests in my table sorting script, which I believe outperforms any other script performing the same functionality:
http://www.JavascriptToolbox.com/lib/table/</description>
		<content:encoded><![CDATA[<p>I did some interesting tests on loop speeds here:<br />
<a href="http://www.mattkruse.com/temp/gb_speed.html" rel="nofollow">http://www.mattkruse.com/temp/gb_speed.html</a></p>
<p>The difference is most noticeable in IE. I use the lessons learned in these tests in my table sorting script, which I believe outperforms any other script performing the same functionality:<br />
<a href="http://www.JavascriptToolbox.com/lib/table/" rel="nofollow">http://www.JavascriptToolbox.com/lib/table/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
