Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Regex profiler

by phizel (Acolyte)
on Jan 17, 2026 at 19:02 UTC ( [id://11167180]=perlquestion: print w/replies, xml ) Need Help??

phizel has asked for the wisdom of the Perl Monks concerning the following question:

Does a profiler exist for regular expressions? The only thing I could find was re's debug mode, but the output isn't very intuitive. I am imagining something like Devel::NYTProf with flame graphs indicating which sections of a regex need optimizing. Take the common whitespace trimming example s/^\s+|\s+$//g; it turns out to sub-optimal because the alternation negates the anchor optimization. Since I can't make heads or tails of re's debug mode output, the only tool in my toolbox for diagnosing regexen is to compare runtimes with Benchmark. Since regular expressions are a feature of many other languages, a better solution might even exist outside of perl.

Replies are listed 'Best First'.
Re: Regex profiler
by Corion (Patriarch) on Jan 18, 2026 at 07:25 UTC
Re: Regex profiler
by choroba (Cardinal) on Jan 17, 2026 at 20:16 UTC
    > a better solution might even exist outside of perl.

    Note that other languages might have similar regex syntax to Perl, but the implementation is definitely different, so profiling/benchmarking it doesn't really help if you're going to use the regex in Perl.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Regex profiler
by LanX (Saint) on Jan 19, 2026 at 13:06 UTC
    Depending on what you mean by "profiling" you can inject Perl (?{code}) snippets into your regex to record the current time. (IMHO that's the most likely approach a third party profiler would take)

    But please be aware that you might get a Heisenbug situation then, because your snippet was hindering some of the many internal heuristics or optimizations.

    Looking into re debug mode before and after those injections is always a good approach.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11167180]
Approved by Athanasius
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2026-02-09 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    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.