Regex not compiled

  1. #1

    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);
                }
            }
        }
    }
  2. #2

    RE: Regex not compiled

    Hi ATSistemi,

    Thanks for pointing this out. I'm not really sure why we don't compile Regex functions. It's certainly something we should have been doing. I'll add this to our TODO and try to get this implemented right away.


    Geoffrey McGill
    Founder
  3. #3

    RE: Regex not compiled

    A ticket has been created for this task, see

    http://extnet.lighthouseapp.com/proj...ns#ticket-22-1


    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 24
    Last Post: Aug 06, 2012, 11:26 AM
  2. Replies: 7
    Last Post: Apr 24, 2012, 4:13 PM
  3. REGEX
    By hbbazan in forum 1.x Help
    Replies: 0
    Last Post: Jan 27, 2010, 4:09 PM
  4. [CLOSED] RegEx problem
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 28, 2009, 12:08 PM
  5. textfield regex using javascript value
    By [WP]joju in forum 1.x Help
    Replies: 1
    Last Post: Sep 04, 2009, 12:29 AM

Posting Permissions