Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-09-23 04:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found