Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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?

Replies are listed 'Best First'.
Re^2: SUBSTR OR REGEX: WHICH WILL YOU FAVOUR?
by vsespb (Chaplain) 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?
[thezip]: Good day Monks

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2017-08-16 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (269 votes). Check out past polls.

    Notices?