Re: strpos() before str_replace()? Or, maybe strtr()? [message #184940 is a reply to message #184938] |
Mon, 17 February 2014 14:14 |
Ben Bacarisse
Messages: 82 Registered: November 2013
Karma:
|
Member |
|
|
"J.O. Aho" <user(at)example(dot)net> writes:
<snip>
> One of the send guys did release an pdf some year ago where he wes
> recommending to strpos check before use of str_replace saying just
> that the strpos was more optimized.
I wonder if any cut-off point was mentioned. It must, at some point,
start to cost more than it saves. For example, if I reverse the
situation given by the OP so that replacements are very common rather
than very rare, adding the strpos call nearly doubles the run time.
Since it nearly haves it when replacements are very rare, I would not be
surprised to find that the break even point is when about half of the
tests will result in a replacement.
Still, the cost or benefit is likely to be insignificant for the vast
majority of PHP programs.
--
Ben.
|
|
|