Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Problem with pre-compiled regex

by moritz (Cardinal)
on Jan 17, 2012 at 15:31 UTC ( [id://948335]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Problem with pre-compiled regex
in thread Problem with pre-compiled regex

Compiling a short and simple regex that consists of only one string literal is so fast that you'll probably have trouble to come up with a benchmark to measure it. So if there is a difference, it'll be too small to be easily observable.

I also think that Perl has an internal cache that avoids recompiling the same regex all over again.

Replies are listed 'Best First'.
Re^4: Problem with pre-compiled regex
by ikegami (Patriarch) on Jan 18, 2012 at 07:03 UTC

    I also think that Perl has an internal cache that avoids recompiling the same regex all over again.

    The ops that compile regex patterns (qr//, m// and s///) remember the last pattern they compiled.

    _ _ _ | | | | | >perl -Mre=debug -e"for (qw( a a a a b b b a )) { qr/$_/ }" 2>&1 | fin +d "Compiling" Compiling REx "a" Compiling REx "b" Compiling REx "a"

    So if you compile the same pattern many times in a row, you'll get savings.

    It's useful for code that looks like

    for my $pat (...) { for my $string (...) { ... $string =~ /$pat/ ... } }

    But not for code that looks like

    for my $string (...) { for my $pat (...) { ... $string =~ /$pat/ ... } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://948335]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found