May 24, 2010, 1:07 PM
Regex not compiled
I've seen the source code of both Coolite 0.8.2 and trunk SVN 1.0, then, i've noticed that you use a certain amount of regexp whose patterns are static. Those regexp could be compiled in a static constructor at the application startup, so we should have a performance gain. Here is a little test for regexp matching with both compiled and not regexp in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace RegExpTest
{
class Program
{
static void Main(string[] args)
{
DateTime start = DateTime.Now;
Compiled();
DateTime end = DateTime.Now;
Console.WriteLine("Compiled " + (end - start).TotalMilliseconds);
start = DateTime.Now;
Normal();
end = DateTime.Now;
Console.WriteLine("Normal " + (end - start).TotalMilliseconds);
Console.ReadKey();
}
private static string str = "<div:layout id=\"[^\"]+\"[^<]*>|</div:layout>";
private const int MAX = 10000000;
private static void Compiled()
{
Regex r = new Regex(str,RegexOptions.Compiled);
for (int i = 0; i < MAX; i++)
{
r.Match("");
}
}
private static void Normal()
{
for (int i = 0; i < MAX; i++)
{
Regex.Match("", str);
}
}
}
}