Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12860
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: strpos() before str_replace()? Or, maybe strtr()? |
| Date | 2014-02-17 18:55 +0100 |
| Message-ID | <bmf0o1Fps1tU1@mid.individual.net> (permalink) |
| References | (2 earlier) <0.9da5fd4e321b89e9adc3.20140216202439GMT.877g8u7qm0.fsf@bsb.me.uk> <bmcm4cFarddU1@mid.individual.net> <0.1d3b7c8128d5ae4333af.20140216205119GMT.87siri6at4.fsf@bsb.me.uk> <bmdldaFgpldU1@mid.individual.net> <0.ebd3223c90ed07830c4a.20140217141429GMT.87k3ct4yii.fsf@bsb.me.uk> |
On 17/02/14 15:14, Ben Bacarisse wrote: > "J.O. Aho" <user@example.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. Don't think he mentioned, I have the document on my PowerPC machine, but that one hasn't been turned on for a year or so. I think there was something about using the position you got from strpos() to limit the scope for which you use str_replace(), but a bit unsure how it was in the example. > 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. I think it was that str_replace was slow on finding the string within and it don't stop at the first find, but has to go through the whole string, but ultimately there will be a break even point, but in normal situations I don't think you will be there. > Still, the cost or benefit is likely to be insignificant for the vast > majority of PHP programs. I think it's the philosophy that decides, one side like microsoft who do not believe in optimization and thinks it's just throw more hardware if there would be issues and another extreme who always goes for optimal optimization and of course a lot of people in between. I think optimization should be done (to a certain level where the time spent will not be too great), as you never will know on what your code will be run, a smart watch with some old SoC, then you will notice the difference while on a TOP 500 Supercomputer you will not notice it, but better be safe than sorry. -- //Aho
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
strpos() before str_replace()? Or, maybe strtr()? Jason C <jwcarlton@gmail.com> - 2014-02-16 01:49 -0800
Re: strpos() before str_replace()? Or, maybe strtr()? bill <william@TechServSys.com> - 2014-02-16 07:10 -0500
Re: strpos() before str_replace()? Or, maybe strtr()? "J.O. Aho" <user@example.net> - 2014-02-16 14:55 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 15:10 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 20:24 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? "J.O. Aho" <user@example.net> - 2014-02-16 21:41 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 20:51 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 22:16 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 23:13 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-18 01:33 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? "J.O. Aho" <user@example.net> - 2014-02-17 06:35 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-17 14:14 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? "J.O. Aho" <user@example.net> - 2014-02-17 18:55 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-17 19:30 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-16 09:15 -0500
Re: strpos() before str_replace()? Or, maybe strtr()? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-16 15:45 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 17:23 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-16 17:41 +0100
Re: strpos() before str_replace()? Or, maybe strtr()? Norman Peelman <npeelman@cfl.rr.com> - 2014-02-16 10:08 -0500
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 19:21 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 20:53 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-17 01:44 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-17 02:19 +0000
Re: strpos() before str_replace()? Or, maybe strtr()? Norman Peelman <npeelman@cfl.rr.com> - 2014-02-16 18:17 -0500
Re: strpos() before str_replace()? Or, maybe strtr()? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-16 20:49 +0000
csiph-web