<?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: C# vs. C#</title>
	<atom:link href="http://lostechies.com/derekgreer/2010/10/20/c-vs-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/</link>
	<description>pursuing well-crafted software</description>
	<lastBuildDate>Wed, 12 Jun 2013 15:15:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: neo</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-43</link>
		<dc:creator>neo</dc:creator>
		<pubDate>Wed, 10 Nov 2010 09:26:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-43</guid>
		<description>yeah thanx for this comparison</description>
		<content:encoded><![CDATA[<p>yeah thanx for this comparison</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarin</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-42</link>
		<dc:creator>Jarin</dc:creator>
		<pubDate>Fri, 29 Oct 2010 21:09:46 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-42</guid>
		<description>Derek, I&#039;ve been playing with new Parallel extensions in .NET 4.0 lately and I converted your example into parallel version:

Parallel.ForEach(Directory.GetFiles(dir, &quot;*.*&quot;, SearchOption.AllDirectories),
                file =&gt; regex.Split(File.ReadAllText(file).ToLower())
                    .ForEach(s =&gt; { lock (monitor) d[s] = 1 + (d.ContainsKey(s) ? d[s] : 0); }));

It&#039;s faster than the original version on my quad core, but not by much. But who cares, it&#039;s been great fun anyway...</description>
		<content:encoded><![CDATA[<p>Derek, I&#8217;ve been playing with new Parallel extensions in .NET 4.0 lately and I converted your example into parallel version:</p>
<p>Parallel.ForEach(Directory.GetFiles(dir, &#8220;*.*&#8221;, SearchOption.AllDirectories),<br />
                file => regex.Split(File.ReadAllText(file).ToLower())<br />
                    .ForEach(s => { lock (monitor) d[s] = 1 + (d.ContainsKey(s) ? d[s] : 0); }));</p>
<p>It&#8217;s faster than the original version on my quad core, but not by much. But who cares, it&#8217;s been great fun anyway&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Clarke</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-41</link>
		<dc:creator>David Clarke</dc:creator>
		<pubDate>Thu, 21 Oct 2010 23:12:41 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-41</guid>
		<description>Yeah thanks Derek, the problem I have now is that my original comment makes me look like a complete imbecile. Suspect it won&#039;t be the last time ;-)</description>
		<content:encoded><![CDATA[<p>Yeah thanks Derek, the problem I have now is that my original comment makes me look like a complete imbecile. Suspect it won&#8217;t be the last time <img src='http://lostechies.com/derekgreer/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derekgreer</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-40</link>
		<dc:creator>derekgreer</dc:creator>
		<pubDate>Thu, 21 Oct 2010 23:02:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-40</guid>
		<description>@Erik - Good to know for future reference.  For this particular test though, the method should do the exact same thing every time so that I get accurate measurements.

@David - You&#039;re right, the code formatting plug-in must have been stripping out the brackets.  It should make more sense now :)
</description>
		<content:encoded><![CDATA[<p>@Erik &#8211; Good to know for future reference.  For this particular test though, the method should do the exact same thing every time so that I get accurate measurements.</p>
<p>@David &#8211; You&#8217;re right, the code formatting plug-in must have been stripping out the brackets.  It should make more sense now <img src='http://lostechies.com/derekgreer/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Clarke</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-39</link>
		<dc:creator>David Clarke</dc:creator>
		<pubDate>Thu, 21 Oct 2010 20:55:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-39</guid>
		<description>Hmm, the square braces and contents are being stripped out prior to displaying the code which is why that line is garbled. &quot;d&quot; is a dictionary so clearly cannot have an int assigned to it. Would be nice if I could drop the code straight into LINQPad and have it run but I guess at worst it was guilty of making me think.</description>
		<content:encoded><![CDATA[<p>Hmm, the square braces and contents are being stripped out prior to displaying the code which is why that line is garbled. &#8220;d&#8221; is a dictionary so clearly cannot have an int assigned to it. Would be nice if I could drop the code straight into LINQPad and have it run but I guess at worst it was guilty of making me think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Clarke</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-38</link>
		<dc:creator>David Clarke</dc:creator>
		<pubDate>Thu, 21 Oct 2010 20:33:46 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-38</guid>
		<description>Line 8 in Solution2 is either incorrect or my browser is doing something funky, should be:

.ForEach(s =&gt; d[s] = 1 + (d.ContainsKey(s) ? d[s] : 0)));</description>
		<content:encoded><![CDATA[<p>Line 8 in Solution2 is either incorrect or my browser is doing something funky, should be:</p>
<p>.ForEach(s => d[s] = 1 + (d.ContainsKey(s) ? d[s] : 0)));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-37</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Thu, 21 Oct 2010 19:06:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-37</guid>
		<description>If you use the static methods on the Regex class and use the Compiled flag, it will cache it in the background.
When using new Regex it will not...
But you are right about that it is reused in the method.</description>
		<content:encoded><![CDATA[<p>If you use the static methods on the Regex class and use the Compiled flag, it will cache it in the background.<br />
When using new Regex it will not&#8230;<br />
But you are right about that it is reused in the method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derekgreer</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-36</link>
		<dc:creator>derekgreer</dc:creator>
		<pubDate>Wed, 20 Oct 2010 23:38:03 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-36</guid>
		<description>@Erik - I&#039;m not sure how the Regex class handles calls to recompile the same regular expression multiple times (i.e. does it cache, or emit new IL every time?), but in this particular example it doesn&#039;t matter.  Because the regular expression is being applied many times, its worth the initial performance hit to compile the regex to gain the performance of applying it to the contents of every file.  I ran some minimal testing to verify this, and the compiled version runs 7% faster on average.</description>
		<content:encoded><![CDATA[<p>@Erik &#8211; I&#8217;m not sure how the Regex class handles calls to recompile the same regular expression multiple times (i.e. does it cache, or emit new IL every time?), but in this particular example it doesn&#8217;t matter.  Because the regular expression is being applied many times, its worth the initial performance hit to compile the regex to gain the performance of applying it to the contents of every file.  I ran some minimal testing to verify this, and the compiled version runs 7% faster on average.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derekgreer</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-35</link>
		<dc:creator>derekgreer</dc:creator>
		<pubDate>Wed, 20 Oct 2010 22:18:43 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-35</guid>
		<description>Ah yes, I am using an extension method here.  I was using ToList().ForEach() in an earlier version and added the extension method to see what performance benefits I would get.  I actually planned to remove this for the article because some early tests indicated the benefit was negligible and I wanted to keep the code as compact as possible, but going back and running the final test again without it shows it does make a bit of difference (30% better vs. 36% better on average).

As far as using foreach directly, this would definitely improve the performance to some degree and I think I&#039;ll go back and test this to satisfy my curiosity, but I think the ForEach() extension makes for more expressive syntax.</description>
		<content:encoded><![CDATA[<p>Ah yes, I am using an extension method here.  I was using ToList().ForEach() in an earlier version and added the extension method to see what performance benefits I would get.  I actually planned to remove this for the article because some early tests indicated the benefit was negligible and I wanted to keep the code as compact as possible, but going back and running the final test again without it shows it does make a bit of difference (30% better vs. 36% better on average).</p>
<p>As far as using foreach directly, this would definitely improve the performance to some degree and I think I&#8217;ll go back and test this to satisfy my curiosity, but I think the ForEach() extension makes for more expressive syntax.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://lostechies.com/derekgreer/2010/10/20/c-vs-c/#comment-34</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Wed, 20 Oct 2010 20:59:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derekgreer/archive/2010/10/20/c-vs-c.aspx#comment-34</guid>
		<description>Compiling a regex and not saving it is bad performance wise. Cache it in a static field or skip compiled flag.</description>
		<content:encoded><![CDATA[<p>Compiling a regex and not saving it is bad performance wise. Cache it in a static field or skip compiled flag.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
