Reply to Re: [PHP] how to post a question?

Your name:

Reply:


Posted by Jochem Maas on 07/25/05 15:21

Ryan A wrote:
> Hey Rich,
>
>
>>>The str_replace calls are kinda expensive IMHO, a good regex would be
>>>better
>
>
>>I'd be interested to see a benchmark (any benchmark) where str_replace is
>>SLOWER than the corresponding Regex...
>
>
> I am not very good with RegEx's myself, and I have never benchmarked any of
> them but
> I was told or read (when i first started learning php) that using multiple
> str_replace()s are
> not a good idea and to use a regex instead.
> (Thats why I wrote the "IMHO",if i was wrong one of the gurus here could
> correct me)
>
> It kind of makes sense, for example using this from the php site:
>
> $phrase = "You should eat fruits, vegetables, and fiber every day.";
> $healthy = array("fruits", "vegetables", "fiber");
> $yummy = array("pizza", "beer", "ice cream");
>
> $newphrase = str_replace($healthy, $yummy, $phrase);
>
> in the above, first it searches the entire phrase for the first parameter
> (fruits) then it starts
> again fro the second parameter (vegetables) etc, if you have a really long
> text it could
> be quite process intensive....because it would have to go through the whole
> text searching for
> the parameters one by one....right?
>
> You're the guy who usually helps me (and a whole lot of others) when we have
> questions

isn't he just! :-) I have to wonder how long his keyboards last ;-), or
whether he retro-fits them with smoke alarms (speedtyping -> overheating ->
fire)

> so I am really interested on your view on this, and why your view favours
> one side more than
> the other.

regexps require a complete engine (in the same way as PHP is a engine)
in order to be parsed. loading/initializing such an engine is heavier than doing a 'simple'
search and replace action.... performance results (between str_replace() and pre_replace()) will
definitely be skewed when comparing simple regexps against a comparable str_replace()
because (to start with) the overhead of calling a function in php (which is why its better
to call str_replace() with arrays in param 1 and 2 rather than calling str_replace()
multiple times)

....also sporadic CPU load due to totally unrelated processes (even when running on
your local machine) can totally skew a benchmark test.

I think you can trust Richard on this one!
and if you don't ... :-) ... then I bet you a beer he'd say "we'll then, why not
test it and see!"



>
> Cheers,
> Ryan
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация