Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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?
Discipulus .. per ear!
[LanX]: LOL
[choroba]: we used to play more :)
Discipulus played the guitar in a ska band 12 elemnts, very fun
[LanX]: well ... the prize for worshipping satan is high ...
[Discipulus]: you value too much your soul LanX
[Eily]: LanX: you mean people end up losing their health insurance?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-03-24 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.