FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » strpos() before str_replace()? Or, maybe strtr()?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: strpos() before str_replace()? Or, maybe strtr()? [message #184940 is a reply to message #184938] Mon, 17 February 2014 14:14 Go to previous messageGo to previous message
Ben Bacarisse is currently offline  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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: getting php mail error info
Next Topic: Declaring an array necessary?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Oct 18 16:13:16 GMT 2024

Total time taken to generate the page: 0.04372 seconds