示例#1
0
        static void CompareMatchEngines(string text, string regex)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();
            System.Text.RegularExpressions.Regex reNet = new System.Text.RegularExpressions.Regex(regex);
            int nMatches = 0;
            foreach (System.Text.RegularExpressions.Match m in reNet.Matches(text)) nMatches++;
            timer.Stop();
            Console.WriteLine("\t.NET library Regex found {0} matches in {1:F3} ms",
                nMatches, timer.Elapsed.TotalMilliseconds);
            double baseline = timer.Elapsed.TotalMilliseconds;

            timer.Restart();
            Regex re = new Regex(regex);
            nMatches = 0;
            foreach (Match m in re.Matches(text)) nMatches++;
            timer.Stop();
            Console.WriteLine("\tBrasswork Regex found {0} matches in {1:F3} ms ({2:F3} of .NET)",
                nMatches, timer.Elapsed.TotalMilliseconds, timer.Elapsed.TotalMilliseconds / baseline);
        }
示例#2
0
 static void TimeMatch(string text, string regex)
 {
     Stopwatch timer = new Stopwatch();
     timer.Start();
     Regex re = new Regex(regex);
     int nMatches = 0;
     foreach (Match m in re.Matches(text)) nMatches++;
     timer.Stop();
     Console.WriteLine("\tBrasswork Regex found {0} matches in {1:F3} ms",
         nMatches, timer.Elapsed.TotalMilliseconds);
 }