<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx</link><description>The .NET Framework System.Text.RegularExpressions.Regex class maintains a cache of parsed regular expressions. The cache improves the performance of methods that create regular expressions, as the Regex class is able to avoid the cost of re-parsing and</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#845474</link><pubDate>Thu, 19 Oct 2006 22:36:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:845474</guid><dc:creator>Nick</dc:creator><description>&lt;p&gt;Does this also applies when RegexOptions.Compiled is set ? Or are compiled Regex always cached ?&lt;/p&gt;
</description></item><item><title>RE: Does this also applies when RegexOptions.Compiled is set ? Or are compiled Regex always cached ?</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#845605</link><pubDate>Thu, 19 Oct 2006 23:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:845605</guid><dc:creator>Josh Free</dc:creator><description>&lt;p&gt;Nick,&lt;/p&gt;
&lt;p&gt;The use of RegexOptions flags does not impact the behavior of the cache. &amp;nbsp;Developers can use the RegexOptions.Compiled flag on either a Regex constructor (to create a Regex instance) or on a static Match method. &amp;nbsp;The Regex object returned from the constructor will not be added to the cache. &amp;nbsp;Remember, the cache does not impact the performance of match operations - it only impacts the performance of regular expression creation.&lt;/p&gt;
&lt;p&gt;For instance calling this constructor multiply times will cause the expression to be compiled each time:&lt;/p&gt;
&lt;p&gt;Regex r1 = new Regex(&amp;quot;abc*&amp;quot;, RegexOptions.Compiled); &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regex r2 = new Regex(&amp;quot;abc*&amp;quot;, RegexOptions.Compiled); &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regex r3 = new Regex(&amp;quot;abc*&amp;quot;, RegexOptions.Compiled); &amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, calling the static method multiple time will use the Regex cache - and subsequent calls may benefit from the cache:&lt;/p&gt;
&lt;p&gt;Regex.Match(&amp;quot;1234bar&amp;quot;, @&amp;quot;(\d*)bar&amp;quot;, RegexOptions.Compiled);&lt;/p&gt;
&lt;p&gt;Regex.Match(&amp;quot;1234bar&amp;quot;, @&amp;quot;(\d*)bar&amp;quot;, RegexOptions.Compiled);&lt;/p&gt;
&lt;p&gt;Regex.Match(&amp;quot;1234bar&amp;quot;, @&amp;quot;(\d*)bar&amp;quot;, RegexOptions.Compiled);&lt;/p&gt;
&lt;p&gt;For more information on Regex compilation, please refer to the &amp;nbsp;&amp;quot;RegularExpression Compilation&amp;quot; section in the January 2006 edition of MSDN Magazine: &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/msdnmag/issues/06/01/CLRInsideOut/"&gt;http://msdn.microsoft.com/msdnmag/issues/06/01/CLRInsideOut/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#845738</link><pubDate>Fri, 20 Oct 2006 00:10:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:845738</guid><dc:creator>nativecpp</dc:creator><description>&lt;p&gt;Hi Josh,&lt;/p&gt;
&lt;p&gt;Thanks for the info. From yr examples, it can be concluded that compiled option is per instance since it compiles 3 times with the same 'abc*', right ?&lt;/p&gt;
</description></item><item><title>re: Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#845788</link><pubDate>Fri, 20 Oct 2006 00:29:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:845788</guid><dc:creator>Kevin Dente</dc:creator><description>&lt;p&gt;How about the assembly cache used by the XmlSerializer? Has the potential for massive leaks present in 1.1 been addressed in 2.0?&lt;/p&gt;
</description></item><item><title>re: Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#849415</link><pubDate>Fri, 20 Oct 2006 15:41:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:849415</guid><dc:creator>Ratnakar</dc:creator><description>&lt;p&gt;Can you please comment on the caching and performance of the following piece of Regex code(both for 1.1 and 2.0) where we are using list of patterns in a loop. I doubt any caching is going on here.&lt;/p&gt;
&lt;p&gt; string[] allowedFormatsWithTimePattern = new string[] {//list of patterns };&lt;/p&gt;
&lt;p&gt;//loop through all the patterns from the array&lt;/p&gt;
&lt;p&gt; for(int indx = 0; indx&amp;lt; allowedFormatsWithTimePattern.Length; indx++)&lt;/p&gt;
&lt;p&gt; {	&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Regex r = new Regex(allowedFormatsWithTimePattern[indx], RegexOptions.Compiled);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if(r.IsMatch(toParse))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{ &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;// do something&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; }&lt;/p&gt;
&lt;p&gt;for better performance should we avoid looping as the number of patterns are fairly constant.&lt;/p&gt;
</description></item><item><title>re: Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework 2.0 [Josh Free]</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#850656</link><pubDate>Sat, 21 Oct 2006 00:36:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:850656</guid><dc:creator>Josh Free</dc:creator><description>&lt;p&gt;Hi Ratnakar,&lt;/p&gt;
&lt;p&gt;Yes, you should avoid calling the Regex constructor in the for-loop. &amp;nbsp;Instead of having a string[] of patterns that you use to instantiate Regex objects again and again, why not create the Regex objects just one time, and save them in a Regex[]?&lt;/p&gt;
&lt;p&gt;Then you can replace these 2 lines inside your for-loop:&lt;/p&gt;
&lt;p&gt;Regex r = new Regex(allowedFormatsWithTimePattern[indx], RegexOptions.Compiled);&lt;/p&gt;
&lt;p&gt;if(r.IsMatch(toParse)) { .... }&lt;/p&gt;
&lt;p&gt;With this 1 line that uses the Regex[], r:&lt;/p&gt;
&lt;p&gt;if(r[indx].IsMatch(toParse)) { .... }&lt;/p&gt;
&lt;p&gt;By making this change, you avoid having to compile the regular expression on the fly, each time in the for-loop.&lt;/p&gt;
</description></item><item><title>UBB解析优化的心得：Regex构造函数的性能</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#4183484</link><pubDate>Thu, 02 Aug 2007 09:39:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4183484</guid><dc:creator>ghj1976</dc:creator><description>&lt;p&gt;昨天和今天，我都在对我之前写的UBB解析代码进行性能优化。优化的结果是：1个具有600多个UBB标签的文本，包含多层UBB嵌套，优化前，解析出这个文本需要2分钟，优化后解析出这个文本需要1秒钟。而这次优化，核心优化的技术只有一点：正则表达式Regex 的构造位置发生变化。下面我就来慢慢来说这次优化。 UBB解析组件的简单介绍 需求： 1、把支持的14个UBB标签解析成不同的Html文本。这14个标签包含：代码高亮标签、禁用UBB标签以及一些通用的UBB标签。 2、一部分UBB 标签支持嵌套的解析，比如对以下文本的解析&lt;/p&gt;
</description></item><item><title>UBB解析优化的心得：Regex构造函数的性能</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#4183780</link><pubDate>Thu, 02 Aug 2007 10:17:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4183780</guid><dc:creator>Joycode@Ab110.com</dc:creator><description>&lt;p&gt;昨天和今天，我都在对我之前写的UBB解析代码进行性能优化。优化的结果是：1个具有600多个UBB标签的文本，包含多层UBB嵌套，优化前，解析出这个文本需要2分钟，优化后解析出这个文本需要1秒钟。而这次优化&lt;/p&gt;
</description></item><item><title>UBB解析优化的心得：Regex构造函数的性能</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#4184024</link><pubDate>Thu, 02 Aug 2007 10:39:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4184024</guid><dc:creator>ghj1976</dc:creator><description>&lt;p&gt;昨天和今天，我都在对我之前写的UBB解析代码进行性能优化。优化的结果是：1个具有600多个UBB标签的文本，包含多层UBB嵌套，优化前，解析出这个文本需要2分钟，优化后解析出这个文本需要1秒钟。而这次优化，核心优化的技术只有一点：正则表达式Regex 的构造位置发生变化。下面我就来慢慢来说这次优化。 UBB解析组件的简单介绍 需求： 1、把支持的14个UBB标签解析成不同的Html文本。这14个标签包含：代码高亮标签、禁用UBB标签以及一些通用的UBB标签。 2、一部分UBB 标签支持嵌套的解析，比如对以下文本的解析&lt;/p&gt;
</description></item><item><title> UBB解析优化的心得：Regex构造函数的性能</title><link>http://blogs.msdn.com/bclteam/archive/2006/10/19/regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx#6786272</link><pubDate>Mon, 17 Dec 2007 07:24:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6786272</guid><dc:creator>csdnexpert</dc:creator><description>&lt;p&gt;昨天和今天，我都在对我之前写的UBB解析代码进行性能优化。优化的结果是：1个具有600多个UBB标签的文本，包含多层UBB嵌套，优化前，解析出这个文本需要2分钟，优化后解析出这个文本需要1秒钟。而这次...&lt;/p&gt;
</description></item></channel></rss>