<?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: Do you really know how for-loops work? How to speed up your for loops</title>
	<atom:link href="http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops</link>
	<description></description>
	<lastBuildDate>Tue, 11 Jun 2013 22:09:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Infernoz</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4826</link>
		<dc:creator>Infernoz</dc:creator>
		<pubDate>Thu, 02 Aug 2007 00:43:28 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4826</guid>
		<description><![CDATA[This is such basic stuff, that it should not need a blog article, but I see so many idiots do this!

Much like the frequent and painful abuse of String in Java, like:
String s = &quot;&quot;
for (int i=0; i=0; ) {} //Note that i does not go negative inside the loop.]]></description>
		<content:encoded><![CDATA[<p>This is such basic stuff, that it should not need a blog article, but I see so many idiots do this!</p>
<p>Much like the frequent and painful abuse of String in Java, like:<br />
String s = &#8220;&#8221;<br />
for (int i=0; i=0; ) {} //Note that i does not go negative inside the loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HuSoft</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4825</link>
		<dc:creator>HuSoft</dc:creator>
		<pubDate>Wed, 18 Jul 2007 16:00:16 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4825</guid>
		<description><![CDATA[You could also do:

for (var i = 0, len = document.getElementById(&#039;t&#039;).getElementsByTagName(&#039;td&#039;).length; i]]></description>
		<content:encoded><![CDATA[<p>You could also do:</p>
<p>for (var i = 0, len = document.getElementById(&#8216;t&#8217;).getElementsByTagName(&#8216;td&#8217;).length; i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nishant Saini</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4824</link>
		<dc:creator>Nishant Saini</dc:creator>
		<pubDate>Wed, 18 Jul 2007 12:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4824</guid>
		<description><![CDATA[Nice Article]]></description>
		<content:encoded><![CDATA[<p>Nice Article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fikovnik</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4823</link>
		<dc:creator>Fikovnik</dc:creator>
		<pubDate>Wed, 18 Jul 2007 10:18:33 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4823</guid>
		<description><![CDATA[it did completely messed up my comments :(]]></description>
		<content:encoded><![CDATA[<p>it did completely messed up my comments <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fikovnik</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4822</link>
		<dc:creator>Fikovnik</dc:creator>
		<pubDate>Wed, 18 Jul 2007 10:17:08 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4822</guid>
		<description><![CDATA[&lt;p&gt;
Even in java:

&lt;/p&gt;&lt;pre&gt;for (int i=0; i=0; i--) {} // comparing with 0 is faster but it leads to slightly not very clean code and the difference is not big ;)&lt;br /&gt;&#160;&lt;/pre&gt;&lt;p&gt;and sure most of the time iterators and enhanced for loops are being used anyway&lt;/p&gt;]]></description>
		<content:encoded><![CDATA[<p>
Even in java:</p>
<pre class="wp-code-highlight prettyprint">for (int i=0; i=0; i--) {} // comparing with 0 is faster but it leads to slightly not very clean code and the difference is not big <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &lt;br /&gt;&amp;nbsp;</pre>
<p>and sure most of the time iterators and enhanced for loops are being used anyway</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p3t0r</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4821</link>
		<dc:creator>p3t0r</dc:creator>
		<pubDate>Tue, 17 Jul 2007 08:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4821</guid>
		<description><![CDATA[The JVM _can_ actually determine if the value could change... but since you&#039;re probably using unsynchronized collections the size of a collection can actually change during your for loop. I&#039;ve seen this latter happening inside Hibernate where they use your proposed construction; it&#039;s faster but with a trade-of.]]></description>
		<content:encoded><![CDATA[<p>The JVM _can_ actually determine if the value could change&#8230; but since you&#8217;re probably using unsynchronized collections the size of a collection can actually change during your for loop. I&#8217;ve seen this latter happening inside Hibernate where they use your proposed construction; it&#8217;s faster but with a trade-of.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Giuca</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4820</link>
		<dc:creator>Matt Giuca</dc:creator>
		<pubDate>Mon, 16 Jul 2007 12:17:55 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4820</guid>
		<description><![CDATA[&quot;And this doesnâ€™t look like an expensive operation in my opinion.&quot;

Well, &quot;document.getElementById(&#039;t&#039;).getElementsByTagName(&#039;td&#039;).length&quot; is quite an expensive operation, particularly in JavaScript. It&#039;s about as expensive an operation as you&#039;re likely to find on the end of a for loop! Remember that even looking up an identifier in JavaScript needs to consult a hash table. So, the above expression would have to:

* Lookup &quot;document&quot; in the global identifiers.
* Lookup &quot;getElementById&quot; in the document object&#039;s dictionary.
* Execute the &quot;getElementById&quot; function, passing &#039;t&#039; as an argument.
* Look throughout the document for an element with the id &#039;t&#039;. This is rather expensive, depending on how the browser indexes element IDs (could be cheap).
* Check to make sure the returned object is not null; if so throw an exception.
* Lookup &quot;getElementsByTagName&quot; on the returned object&#039;s dictionary.
* Execute the &quot;getElementsByTagName&quot; function, passing &#039;td&#039; as an argument.
* The killer: Search the entire document tree, doing a string comparison against _every_ element&#039;s tag name, and doing a list insert for all successful elements. The browser could intelligently hash tag names but I don&#039;t think they do.
* Finally lookup &quot;length&quot; in the returned list object&#039;s dictionary.
* And execute the &quot;length&quot; function, which cheaply returns the length as an integer.

So it is rather a good example then, of the perfect expression which deserves to be thrown with great vigour out of the loop body!]]></description>
		<content:encoded><![CDATA[<p>&#8220;And this doesnâ€™t look like an expensive operation in my opinion.&#8221;</p>
<p>Well, &#8220;document.getElementById(&#8216;t&#8217;).getElementsByTagName(&#8216;td&#8217;).length&#8221; is quite an expensive operation, particularly in JavaScript. It&#8217;s about as expensive an operation as you&#8217;re likely to find on the end of a for loop! Remember that even looking up an identifier in JavaScript needs to consult a hash table. So, the above expression would have to:</p>
<p>* Lookup &#8220;document&#8221; in the global identifiers.<br />
* Lookup &#8220;getElementById&#8221; in the document object&#8217;s dictionary.<br />
* Execute the &#8220;getElementById&#8221; function, passing &#8216;t&#8217; as an argument.<br />
* Look throughout the document for an element with the id &#8216;t&#8217;. This is rather expensive, depending on how the browser indexes element IDs (could be cheap).<br />
* Check to make sure the returned object is not null; if so throw an exception.<br />
* Lookup &#8220;getElementsByTagName&#8221; on the returned object&#8217;s dictionary.<br />
* Execute the &#8220;getElementsByTagName&#8221; function, passing &#8216;td&#8217; as an argument.<br />
* The killer: Search the entire document tree, doing a string comparison against _every_ element&#8217;s tag name, and doing a list insert for all successful elements. The browser could intelligently hash tag names but I don&#8217;t think they do.<br />
* Finally lookup &#8220;length&#8221; in the returned list object&#8217;s dictionary.<br />
* And execute the &#8220;length&#8221; function, which cheaply returns the length as an integer.</p>
<p>So it is rather a good example then, of the perfect expression which deserves to be thrown with great vigour out of the loop body!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeroen van Wilgenburg</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4819</link>
		<dc:creator>Jeroen van Wilgenburg</dc:creator>
		<pubDate>Mon, 16 Jul 2007 12:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4819</guid>
		<description><![CDATA[Thanks prashant.
&gt;&gt; sezgin: How can the JVM know that value of the method you&#039;re calling never changes? And when the JVM optimizes this I should&#039;ve got other test results. I&#039;m sure the JVM optimizes certain things, but it is better when you optimze the for loops yourself, because the JVM doesn&#039;t know everything.]]></description>
		<content:encoded><![CDATA[<p>Thanks prashant.<br />
&gt;&gt; sezgin: How can the JVM know that value of the method you&#8217;re calling never changes? And when the JVM optimizes this I should&#8217;ve got other test results. I&#8217;m sure the JVM optimizes certain things, but it is better when you optimze the for loops yourself, because the JVM doesn&#8217;t know everything.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prashant</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4818</link>
		<dc:creator>prashant</dc:creator>
		<pubDate>Mon, 16 Jul 2007 10:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4818</guid>
		<description><![CDATA[Hi,

Good simple article.I liked it and am also not aware of this till now having almost 3.7 yrs experience. :-)

Thanks
Prashant]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Good simple article.I liked it and am also not aware of this till now having almost 3.7 yrs experience. <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Thanks<br />
Prashant</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sezgin</title>
		<link>http://technology.amis.nl/2007/07/15/do-you-really-know-how-for-loops-work-how-to-speed-up-your-for-loops/#comment-4817</link>
		<dc:creator>sezgin</dc:creator>
		<pubDate>Mon, 16 Jul 2007 00:02:57 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=2308#comment-4817</guid>
		<description><![CDATA[JVM optimizes this kind of things .So I don&#039;t worry about that for Java.But worry for javascript.]]></description>
		<content:encoded><![CDATA[<p>JVM optimizes this kind of things .So I don&#8217;t worry about that for Java.But worry for javascript.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
