Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by samy_kumar (Scribe)
on Feb 18, 2005 at 13:08 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found