<?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: Are C# .Net Regular Expressions Fast Enough for You?</title>
	<atom:link href="http://OmegaCoder.com/?feed=rss2&#038;p=324" rel="self" type="application/rss+xml" />
	<link>http://OmegaCoder.com/?p=324</link>
	<description>Technology blog written by a Microsoft C# MVP</description>
	<lastBuildDate>Tue, 07 Sep 2010 14:35:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: BillyD</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-1109</link>
		<dc:creator>BillyD</dc:creator>
		<pubDate>Sat, 12 Jun 2010 22:09:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-1109</guid>
		<description>change highway to

        public static int Highway(string text)
        {
            int value = 0;
            int indexOf = text.IndexOf(&quot;value=\&quot;&quot;);

            if (indexOf &gt;= 0)
            {
                indexOf += &quot;value=\&quot;&quot;.Length;
                int endIndex = text.IndexOf(&quot;\&quot;&quot;, indexOf);
                int.TryParse(text.Substring(indexOf, (endIndex &gt; 0 ? endIndex - indexOf : 0)), out value);
            }
            return value;
        }

and give it a try now.
On my machine, regex is just over 3x slower 
Non Regex:        38.5628        Avg Per Run:        0.000385628
Regex:                122.995        Avg Per Run:        0.00122995


I&#039;m not saying don&#039;t use the regex though; especially for this example. I just don&#039;t like how often people jump to support regex.</description>
		<content:encoded><![CDATA[<p>change highway to</p>
<p>        public static int Highway(string text)<br />
        {<br />
            int value = 0;<br />
            int indexOf = text.IndexOf(&#8220;value=\&#8221;");</p>
<p>            if (indexOf &gt;= 0)<br />
            {<br />
                indexOf += &#8220;value=\&#8221;".Length;<br />
                int endIndex = text.IndexOf(&#8220;\&#8221;", indexOf);<br />
                int.TryParse(text.Substring(indexOf, (endIndex &gt; 0 ? endIndex &#8211; indexOf : 0)), out value);<br />
            }<br />
            return value;<br />
        }</p>
<p>and give it a try now.<br />
On my machine, regex is just over 3x slower<br />
Non Regex:        38.5628        Avg Per Run:        0.000385628<br />
Regex:                122.995        Avg Per Run:        0.00122995</p>
<p>I&#8217;m not saying don&#8217;t use the regex though; especially for this example. I just don&#8217;t like how often people jump to support regex.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: omegaman</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-230</link>
		<dc:creator>omegaman</dc:creator>
		<pubDate>Mon, 22 Jun 2009 21:05:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-230</guid>
		<description>Thanks Fernando! I will re-evaluate the test. The code did come from someone else and I didn&#039;t look at it accordingly; my bad.

But it would make sense, now that I look at the code, for dealing with case does add time in both Regex and non regex operations. So sounds like it is time for another test!</description>
		<content:encoded><![CDATA[<p>Thanks Fernando! I will re-evaluate the test. The code did come from someone else and I didn&#8217;t look at it accordingly; my bad.</p>
<p>But it would make sense, now that I look at the code, for dealing with case does add time in both Regex and non regex operations. So sounds like it is time for another test!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando Nicolet</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-229</link>
		<dc:creator>Fernando Nicolet</dc:creator>
		<pubDate>Mon, 22 Jun 2009 16:56:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-229</guid>
		<description>Hi William. Great post as usual, I always wondered about benchmarks comparing RegEx solutions vs regular string operations, and the result is amazing. I totally agree that regular expressions are the way to go in almost every common scenario.

Anyways, I&#039;m never satisfied with just evaluating results if I don&#039;t analyze the process by which they are obtained. Well, at least when I understand the process. So after some copy &amp; pasting, I got the same results as you did, but there was something that came into my attention, and that was the way you compared the strings in &quot;Highway&quot;. In my experience, ToLower or ToUpper comparisons are way slower than using StringComparison.InvariantCultureIgnoreCase, so I went ahead and changed it. As expected, there was a slight improvement, but the conclusion I got after that was more important: Highway is case-insensitive and MyWay isn&#039;t. Therefor I went ahead and changed Highway to be case sensitive as well and now the results are pretty different. Highway takes less than half the time as MyWay! I&#039;d thought it would be fair for the string class that I shared my results ;)

Well, having said all that, still the answer to you question is: Yes! It definitely is fast enough for me. Even with the broader difference in performance. A better use and understanding of regular expressions has been in my todo list like forever. Unless performance is explicitly required, I always favor simplicity and versatility over performance, and this is exactly that.</description>
		<content:encoded><![CDATA[<p>Hi William. Great post as usual, I always wondered about benchmarks comparing RegEx solutions vs regular string operations, and the result is amazing. I totally agree that regular expressions are the way to go in almost every common scenario.</p>
<p>Anyways, I&#8217;m never satisfied with just evaluating results if I don&#8217;t analyze the process by which they are obtained. Well, at least when I understand the process. So after some copy &amp; pasting, I got the same results as you did, but there was something that came into my attention, and that was the way you compared the strings in &#8220;Highway&#8221;. In my experience, ToLower or ToUpper comparisons are way slower than using StringComparison.InvariantCultureIgnoreCase, so I went ahead and changed it. As expected, there was a slight improvement, but the conclusion I got after that was more important: Highway is case-insensitive and MyWay isn&#8217;t. Therefor I went ahead and changed Highway to be case sensitive as well and now the results are pretty different. Highway takes less than half the time as MyWay! I&#8217;d thought it would be fair for the string class that I shared my results <img src='http://OmegaCoder.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Well, having said all that, still the answer to you question is: Yes! It definitely is fast enough for me. Even with the broader difference in performance. A better use and understanding of regular expressions has been in my todo list like forever. Unless performance is explicitly required, I always favor simplicity and versatility over performance, and this is exactly that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Al Tenhundfeld</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-228</link>
		<dc:creator>Al Tenhundfeld</dc:creator>
		<pubDate>Wed, 17 Jun 2009 15:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-228</guid>
		<description>Thanks for the comparison. I completely agree with the sentiment. I wanted to see how much worse uncompiled Regex would perform. I ran the same comparison at 10 different random times throughout the morning and got these averaged results.

Non Regex:	  199.9204	Avg Per Run:	0.001999204
Regex Compiled:	  242.9104	Avg Per Run:	0.002429104
Regex Uncompiled: 326.9396	Avg Per Run:	0.003269396</description>
		<content:encoded><![CDATA[<p>Thanks for the comparison. I completely agree with the sentiment. I wanted to see how much worse uncompiled Regex would perform. I ran the same comparison at 10 different random times throughout the morning and got these averaged results.</p>
<p>Non Regex:	  199.9204	Avg Per Run:	0.001999204<br />
Regex Compiled:	  242.9104	Avg Per Run:	0.002429104<br />
Regex Uncompiled: 326.9396	Avg Per Run:	0.003269396</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Grove</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-227</link>
		<dc:creator>John Grove</dc:creator>
		<pubDate>Wed, 17 Jun 2009 00:36:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-227</guid>
		<description>Excellent analysis of such a widely ignored and dismissed topic which many consider &quot;esoteric&quot;. Regex is the text pattern standard for text searching and parsing.

You hit the nail on the head because I was one who ignored it for years until I finally buckled down and began learning it. Now my views have been opened up to a whole new way to do things a lot more simpler and elegantly.

Thank you William.</description>
		<content:encoded><![CDATA[<p>Excellent analysis of such a widely ignored and dismissed topic which many consider &#8220;esoteric&#8221;. Regex is the text pattern standard for text searching and parsing.</p>
<p>You hit the nail on the head because I was one who ignored it for years until I finally buckled down and began learning it. Now my views have been opened up to a whole new way to do things a lot more simpler and elegantly.</p>
<p>Thank you William.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les Potter</title>
		<link>http://OmegaCoder.com/?p=324&#038;cpage=1#comment-226</link>
		<dc:creator>Les Potter</dc:creator>
		<pubDate>Wed, 17 Jun 2009 00:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.omegacoder.com/?p=324#comment-226</guid>
		<description>Versatility verses speed.  Regex wins hands-down with versatility.  And it looks like speed isn&#039;t to shabby.  Thanks for the legwork.</description>
		<content:encoded><![CDATA[<p>Versatility verses speed.  Regex wins hands-down with versatility.  And it looks like speed isn&#8217;t to shabby.  Thanks for the legwork.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
