Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: SUBSTR OR REGEX: WHICH WILL YOU FAVOUR?

by bulk88 (Priest)
on Oct 20, 2013 at 01:06 UTC ( #1058967=note: print w/ replies, xml ) Need Help??


in reply to SUBSTR OR REGEX: WHICH WILL YOU FAVOUR?

substr is always faster than a regex. index is always faster than a regex. Combining the 2, they are faster than a regex. But if you add an if else block or more than 1 index, they start being the same speed as a regex. Regex parsing logic is faster than Perl optree logic. But a regex can never beat memcpy (AKA substr) and strstr (AKA index).


Comment on Re: SUBSTR OR REGEX: WHICH WILL YOU FAVOUR?
Re^2: SUBSTR OR REGEX: WHICH WILL YOU FAVOUR?
by vsespb (Hermit) on Oct 26, 2013 at 22:11 UTC
    Recently I found simple regexp $x =~ /Something/ is just 5%-10% slower than index (on small inputs)

    I actually can't see reason why perl won't recognize /Something/ as something that can be replaced by index() at compile time

    And 10% is just implementation overhead.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2015-07-06 01:42 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