Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?

( #40552=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > Regex anchor speed ?: Is /^.*X/ faster than /X/ ? contributed by Fastolfe

I benchmarked it:

The string: "now is the time for all good monks to come to the aid of their perl". The results:

Benchmark: timing 5000000 iterations of /.*perl/, /^.*perl/, /perl/... /.*perl/: 43 secs (41.48 usr 0.00 sys = 41.48 cpu) /^.*perl/: 38 secs (36.20 usr 0.00 sys = 36.20 cpu) /perl/: 29 secs (28.96 usr 0.00 sys = 28.96 cpu)
So yah, a standalone /match/ is going to be a bit faster.

Comment on Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-05 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls