<?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: Enumeration isn&#8217;t cheap</title>
	<atom:link href="http://blog.lab49.com/archives/238/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.lab49.com/archives/238</link>
	<description>Technology and industry insights from Lab49.</description>
	<lastBuildDate>Sat, 24 Sep 2011 08:33:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Bill</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-1168</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Wed, 10 May 2006 19:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-1168</guid>
		<description>for (int i...
{
int x = ((SomeClass)list[i]).Val;
}</description>
		<content:encoded><![CDATA[<p>for (int i&#8230;<br />
{<br />
int x = ((SomeClass)list[i]).Val;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-1167</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Wed, 10 May 2006 19:24:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-1167</guid>
		<description>Hmm...looks like my sample was clipped. I was trying to emphasize the following amendment to the for (int i...loop:

int length = list.Count;
for (int i = 0; i </description>
		<content:encoded><![CDATA[<p>Hmm&#8230;looks like my sample was clipped. I was trying to emphasize the following amendment to the for (int i&#8230;loop:</p>
<p>int length = list.Count;<br />
for (int i = 0; i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-1166</link>
		<dc:creator>Bill</dc:creator>
		<pubDate>Wed, 10 May 2006 19:22:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-1166</guid>
		<description>Another thing worth noting here is that in more typical usage of an ArrayList&#039;s indexer, a cast is required. When the above sample is modified in the following fashion, results converge significantly to:

Enumerator: 328.1376 Indexing: 125.0048

private void button1_Click(object sender, System.EventArgs e)
		{
			ArrayList list = new ArrayList();
			for (int i = 0; i </description>
		<content:encoded><![CDATA[<p>Another thing worth noting here is that in more typical usage of an ArrayList&#8217;s indexer, a cast is required. When the above sample is modified in the following fashion, results converge significantly to:</p>
<p>Enumerator: 328.1376 Indexing: 125.0048</p>
<p>private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			ArrayList list = new ArrayList();<br />
			for (int i = 0; i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Flemmer</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-1064</link>
		<dc:creator>Luke Flemmer</dc:creator>
		<pubDate>Sun, 30 Apr 2006 17:21:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-1064</guid>
		<description>There are some interesting imporvements in 2.0, made possible through the introduction of generic types. Specifcally, the boxing/unboxing costs associated with value types in a collection, or even just the cost of the downcast from Object, can now be avoided. There is quite a nice article on it here: http://msdn.microsoft.com/msdnmag/issues/04/05/C20/</description>
		<content:encoded><![CDATA[<p>There are some interesting imporvements in 2.0, made possible through the introduction of generic types. Specifcally, the boxing/unboxing costs associated with value types in a collection, or even just the cost of the downcast from Object, can now be avoided. There is quite a nice article on it here: <a href="http://msdn.microsoft.com/msdnmag/issues/04/05/C20/" rel="nofollow">http://msdn.microsoft.com/msdnmag/issues/04/05/C20/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Morrison</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-1060</link>
		<dc:creator>Joe Morrison</dc:creator>
		<pubDate>Sat, 29 Apr 2006 22:34:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-1060</guid>
		<description>Did either of you try this with CLR 2.0? I did, and the  Enumerator version varied between 1.5-2x worse than the index based version. Nothing as bad as 5-10x worse though. Looks like Microsoft has been working on this.</description>
		<content:encoded><![CDATA[<p>Did either of you try this with CLR 2.0? I did, and the  Enumerator version varied between 1.5-2x worse than the index based version. Nothing as bad as 5-10x worse though. Looks like Microsoft has been working on this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Flemmer</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-889</link>
		<dc:creator>Luke Flemmer</dc:creator>
		<pubDate>Mon, 10 Apr 2006 20:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-889</guid>
		<description>Yes. I&#039;m certainly not advancing this is as the canonical testing suite... Another thing it doesn&#039;t demonstrate is that the cost doesn&#039;t just exist for large collections. Iterations over small collections that are called frequently can actually be worse, since you incurr the cost of creating the Enumerator, and then later GC&#039;ing it.</description>
		<content:encoded><![CDATA[<p>Yes. I&#8217;m certainly not advancing this is as the canonical testing suite&#8230; Another thing it doesn&#8217;t demonstrate is that the cost doesn&#8217;t just exist for large collections. Iterations over small collections that are called frequently can actually be worse, since you incurr the cost of creating the Enumerator, and then later GC&#8217;ing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Morton</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-888</link>
		<dc:creator>Damien Morton</dc:creator>
		<pubDate>Mon, 10 Apr 2006 19:35:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-888</guid>
		<description>Umm, I was trying to show that you should accumulate all of the hashcodes your grab, i.e. x += o.GetHashCode()</description>
		<content:encoded><![CDATA[<p>Umm, I was trying to show that you should accumulate all of the hashcodes your grab, i.e. x += o.GetHashCode()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Morton</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-887</link>
		<dc:creator>Damien Morton</dc:creator>
		<pubDate>Mon, 10 Apr 2006 19:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-887</guid>
		<description>When doing these kinds of things, I also try to ensure that the code I am testing in the inner loop actually _does_ something, otherwise it can be optimised away.

x = 0;
int t0 = Environment.TickCount;
for (int i = 0; i </description>
		<content:encoded><![CDATA[<p>When doing these kinds of things, I also try to ensure that the code I am testing in the inner loop actually _does_ something, otherwise it can be optimised away.</p>
<p>x = 0;<br />
int t0 = Environment.TickCount;<br />
for (int i = 0; i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Flemmer</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-885</link>
		<dc:creator>Luke Flemmer</dc:creator>
		<pubDate>Mon, 10 Apr 2006 18:40:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-885</guid>
		<description>Good point. Reversing them the ratio falls to about 7x worse for the enumerator.</description>
		<content:encoded><![CDATA[<p>Good point. Reversing them the ratio falls to about 7x worse for the enumerator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Morton</title>
		<link>http://blog.lab49.com/archives/238/comment-page-1#comment-884</link>
		<dc:creator>Damien Morton</dc:creator>
		<pubDate>Mon, 10 Apr 2006 18:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.lab49.com/?p=238#comment-884</guid>
		<description>I would check this again, with the order of your tests reversed. I believe that Object.GetHashCode() is more expensive the first time it is called.

Certainly, in comparing enumerators with indexing, you will find differences, but the magnitude of the differences you are finding seems out of whack.</description>
		<content:encoded><![CDATA[<p>I would check this again, with the order of your tests reversed. I believe that Object.GetHashCode() is more expensive the first time it is called.</p>
<p>Certainly, in comparing enumerators with indexing, you will find differences, but the magnitude of the differences you are finding seems out of whack.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

