Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Analyzing regular expression performance

by mantadin (Beadle)
on May 12, 2006 at 11:30 UTC ( [id://549039]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Analyzing regular expression performance

to analyse a regex, you can use YAPE::Regex::Explain.

update: one example: perl -MYAPE::Regex::Explain -e 'print YAPE::Regex::Explain->new(qr/(<a\s(?:[^>](?!href))*href\s*)(&(&[^;]+;)?(?:.(?!\3))+(?:\3)?)([^>]+>)/)->explain'

For the performance, one thing that comes to my mind is the /o qualifier to compile once only. And if You still suffer from perfomance issues, You might want to use a debugger and/or profiler. But in that case, maybe You should first try to 'divide and conquer' the regexp into a few smaller ones.

Replies are listed 'Best First'.
Re^2: Analyzing regular expression performance
by duff (Parson) on May 12, 2006 at 14:37 UTC
    For the performance, one thing that comes to my mind is the /o qualifier to compile once only

    Yikes! Don't ever recommend that. It's rarely needed and causes more trouble than it is worth. Perl already does optimizations for patterns that contain no variables and for patterns that do contain variables that don't vary over the lifetime of the code in which the pattern appears, so /o won't buy you anything there. If you really need the "compile once" idea, just use qr/.../

      what You say makes sense to me. At least the 'wont buy you anything' part. What I dont understand: how can the /o cause trouble?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://549039]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.