Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???

by samy_kumar (Scribe)
on Feb 18, 2005 at 13:08 UTC ( #432311=note: print w/replies, xml ) Need Help??


in reply to Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???  

Hi, I think the problem is with this line.
my $regex = qr /(?:$regexstr)/;
because perl compiles this patern again & again in the foreach loop.
foreach my $stringlength (100,1000,10000,100000)
If you use this pattern
my $regex = qr /(?:$regexstr)/o;
instead of
my $regex = qr /(?:$regexstr)/;
It will be fast. Since it compiles the pattern only once.

Replies are listed 'Best First'.
Re^2: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
by Roy Johnson (Monsignor) on Feb 18, 2005 at 13:14 UTC
    No, Perl compiles the regex once where it is defined with qr.

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-06-25 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (81 votes). Check out past polls.

    Notices?