in reply to Re^2: Slowdown when using Moose::Util::TypeConstraints with Regexp::Common
in thread Slowdown when using Moose::Util::TypeConstraints with Regexp::Common

Basically all your versions, except AdressA, now use a single static regex, so they get compiled once at compile time, hence few or no differences. The Regexp::Common version cannot be optimized in that way, unless you force it to become static by using qr//. Such is the price you pay for flexibility.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

  • Comment on Re^3: Slowdown when using Moose::Util::TypeConstraints with Regexp::Common
  • Download Code

Replies are listed 'Best First'.
Re^4: Slowdown when using Moose::Util::TypeConstraints with Regexp::Common (recompile)
by tye (Sage) on Sep 03, 2008 at 04:10 UTC

    Actually, using Regexp::Common w/o qr// should result in the regex being compiled the first time that it is used. Each time it is used after that, a string comparison should be used to see if the regex needs to be recompiled. So it should be only compiled once and only an extra string compare will be done each time it is run.

    - tye        

      Yes, but the problem is creating said string. The $RE{...} expression dives down in a multi-level hash, which is tied on each level, and at the bottom, it calls a function.

      It may not be so slow as compiling a regexp, but it is the most likely cause of AddressA being the slowest of the four.

Re^4: Slowdown when using Moose::Util::TypeConstraints with Regexp::Common
by kevbot (Vicar) on Sep 03, 2008 at 00:13 UTC
    Thank you for your replies. They have been helpful. It was not obvious to me that the AddressC regexp would be compiled once at compile time...but it makes sense to me now.