<?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: Improve your code: Regex creation is expensive</title>
	<atom:link href="http://www.acorns.com.au/blog/?feed=rss2&#038;p=136" rel="self" type="application/rss+xml" />
	<link>http://www.acorns.com.au/blog/?p=136</link>
	<description></description>
	<lastBuildDate>Wed, 20 Jan 2010 18:59:44 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Venkatesh</title>
		<link>http://www.acorns.com.au/blog/?p=136&#038;cpage=1#comment-168</link>
		<dc:creator>Venkatesh</dc:creator>
		<pubDate>Tue, 17 Feb 2009 02:58:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=136#comment-168</guid>
		<description>very nice....</description>
		<content:encoded><![CDATA[<p>very nice&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: igorbrejc.net &#187; Visiting Regex.Replace() Method And MatchEvaluator Delegate</title>
		<link>http://www.acorns.com.au/blog/?p=136&#038;cpage=1#comment-167</link>
		<dc:creator>igorbrejc.net &#187; Visiting Regex.Replace() Method And MatchEvaluator Delegate</dc:creator>
		<pubDate>Mon, 05 Jan 2009 17:09:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=136#comment-167</guid>
		<description>[...] Creating Regex objects is expensive, so it&#8217;s better to instantiate them once as static members. Using RegexOptions.Compiled is also recommended, as is reading Jeff Atwood&#8217;s post about it. [...]</description>
		<content:encoded><![CDATA[<p>[...] Creating Regex objects is expensive, so it&#8217;s better to instantiate them once as static members. Using RegexOptions.Compiled is also recommended, as is reading Jeff Atwood&#8217;s post about it. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anon</title>
		<link>http://www.acorns.com.au/blog/?p=136&#038;cpage=1#comment-166</link>
		<dc:creator>Anon</dc:creator>
		<pubDate>Mon, 22 Dec 2008 10:11:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=136#comment-166</guid>
		<description>You should repeat the tests using the Regex static functions in addition to testing versus precompiled regex&#039;s. Consider using the Regex static methods instead of using RegexOptions.Compiled.

I too was of your opinion until I read about improvements since .net 2.0 -the static methods now cache the parsed regex and are just about as fast. The implications are that once cached, you no longer suffer the process of rebuilding them (assuming they weren&#039;t pushed from the cache).

IIRC the current thinking is to either use the static functions because they&#039;re efficient, generally have a lower memory overhead, and memory is reclaimed if they&#039;re not needed (as opposed to loaded statically). If you do determine that your regex&#039;s need to be compiled, you should go the extra step and precompile them into an assembly. &lt;a href=&quot;http://en.csharp-online.net/CSharp_Regular_Expression_Recipes—Compiling_Regular_Expressions&quot; rel=&quot;nofollow&quot;&gt;C# Regular Expression Recipes—Compiling Regular Expressions&lt;/a&gt;

Also, a second point is you should be measuring the time it takes to compile the regex, and the differing memory footprints. You make light of the fact that compiling the regex is slow, but at the same time try to show that test2 is a factor of 10 slower than test 1. Additionally, if you take the creation of the regex outside of the for loop, how do the results differ. Further, you should compare simple regex&#039;s to complicated ones to get a better feel for how they really compare.</description>
		<content:encoded><![CDATA[<p>You should repeat the tests using the Regex static functions in addition to testing versus precompiled regex&#8217;s. Consider using the Regex static methods instead of using RegexOptions.Compiled.</p>
<p>I too was of your opinion until I read about improvements since .net 2.0 -the static methods now cache the parsed regex and are just about as fast. The implications are that once cached, you no longer suffer the process of rebuilding them (assuming they weren&#8217;t pushed from the cache).</p>
<p>IIRC the current thinking is to either use the static functions because they&#8217;re efficient, generally have a lower memory overhead, and memory is reclaimed if they&#8217;re not needed (as opposed to loaded statically). If you do determine that your regex&#8217;s need to be compiled, you should go the extra step and precompile them into an assembly. <a href="http://en.csharp-online.net/CSharp_Regular_Expression_Recipes—Compiling_Regular_Expressions" rel="nofollow">C# Regular Expression Recipes—Compiling Regular Expressions</a></p>
<p>Also, a second point is you should be measuring the time it takes to compile the regex, and the differing memory footprints. You make light of the fact that compiling the regex is slow, but at the same time try to show that test2 is a factor of 10 slower than test 1. Additionally, if you take the creation of the regex outside of the for loop, how do the results differ. Further, you should compare simple regex&#8217;s to complicated ones to get a better feel for how they really compare.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sammy Larbi</title>
		<link>http://www.acorns.com.au/blog/?p=136&#038;cpage=1#comment-165</link>
		<dc:creator>Sammy Larbi</dc:creator>
		<pubDate>Wed, 17 Dec 2008 13:29:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=136#comment-165</guid>
		<description>You missed the obvious test case: Creating the Regex outside the for loop but not static. Of course creating an object 10000 times is going to be a bit more expensive than creating it once.

And besides, how often are you going to create a Regex 10000 times? It doesn&#039;t seem to make a human-noticeable difference even if you mistakenly stick it in the loop, but the question remains.</description>
		<content:encoded><![CDATA[<p>You missed the obvious test case: Creating the Regex outside the for loop but not static. Of course creating an object 10000 times is going to be a bit more expensive than creating it once.</p>
<p>And besides, how often are you going to create a Regex 10000 times? It doesn&#8217;t seem to make a human-noticeable difference even if you mistakenly stick it in the loop, but the question remains.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David L. Penton</title>
		<link>http://www.acorns.com.au/blog/?p=136&#038;cpage=1#comment-164</link>
		<dc:creator>David L. Penton</dc:creator>
		<pubDate>Tue, 16 Dec 2008 16:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=136#comment-164</guid>
		<description>Blogged response: http://pentonizer.com/csharp/regex-precompilation/</description>
		<content:encoded><![CDATA[<p>Blogged response: <a href="http://pentonizer.com/csharp/regex-precompilation/" rel="nofollow">http://pentonizer.com/csharp/regex-precompilation/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
