<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" 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/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Rex Flex &#187; .NET</title> <atom:link href="http://rexflex.net/tag/net/feed/" rel="self" type="application/rss+xml" /><link>http://rexflex.net</link> <description>Rants of a software developer</description> <lastBuildDate>Fri, 02 Sep 2011 16:54:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Performance of Different Types of For Loops</title><link>http://rexflex.net/2007/07/performance-of-different-types-of-for-loops/</link> <comments>http://rexflex.net/2007/07/performance-of-different-types-of-for-loops/#comments</comments> <pubDate>Fri, 13 Jul 2007 05:55:22 +0000</pubDate> <dc:creator>Rex Morgan</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[best practices]]></category> <category><![CDATA[CLR]]></category> <category><![CDATA[for loop]]></category> <category><![CDATA[performance]]></category><guid isPermaLink="false">http://www.rexflex.net/archives/2007/07/12/performance-of-different-types-of-for-loops/</guid> <description><![CDATA[In an old post I found online here the author asks how you would go about writing a simple for loop. I was bored tonight, so I wrote a simple program to time several different types of loops to confirm which is the fastest at iterating through a generic list, yes&#8230; that bored. My list [...]]]></description> <content:encoded><![CDATA[<p>In an old post I found online <a href="http://www.netcrucible.com/blog/2004/04/21/loopy-decisions/">here</a> the author asks how you would go about writing a simple for loop.  I was bored tonight, so I wrote a simple program to time several different types of loops to confirm which is the fastest at iterating through a generic list, yes&#8230; that bored.  My list contained 67,108,863 integers.</p><p>Here are the results:<br /> <strong>Foreach loop: 1185.8ms</strong></p><pre>
<code>int tmp;
foreach (int i in array)
{
tmp = i;
}</code>
</pre><p><strong>Standard for loop: 932.1ms</strong></p><pre>
<code>int tmp;
for (int i = 0; i &lt; array.Count; i++)
{
tmp = array[i];
}</code></pre><p><strong>Optimized for loop: 726.1ms</strong></p><pre>
<code>int tmp;
int cnt = array.Count;
for (int i = 0; i &lt; cnt; ++i)
{
tmp = array[i];
}</code></pre>]]></content:encoded> <wfw:commentRss>http://rexflex.net/2007/07/performance-of-different-types-of-for-loops/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 298/305 objects using disk: basic
Content Delivery Network via Rackspace Cloud Files: c520208.r8.cf2.rackcdn.com

Served from: rexflex.net @ 2012-05-22 19:56:38 -->
