Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Analyzing regular expression performance

by grinder (Bishop)
on May 12, 2006 at 11:31 UTC ( [id://549042]=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

Are there tools or general methods for breaking down an expression

The 'debug' mode of re will let you see how the expression is compiled, and how it behaves when matching. It is usually obvious to see where backtracking is taking place.

#! /usr/bin/perl use strict; use re 'debug'; print "easy\n" if 'simple' =~ /simple/; print "hard\n" if 'simple' =~ /^.[i-k]\lM(?:pla|plo|pl)(?:oink)?e$/;

Another trick is to "leave crumbs" is the pattern, to see how often the engine runs over a particular section of the pattern, for instance:

perl -le '(q(x) x 100) =~ /^x(((((x{2,5})x{2,5})x{2,4})x?)x?(?{$hit++} +))$/; print $hit'

• another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://549042]
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.