Ilia A. wrote:
I may be wrong since I haven't profiled this, but my understanding is
that str_replace is much faster than doing either of the regex
replacements. For that reason alone, there is a use for it.


Normally it would be quite faster, however once case sensitivity is added to the mix I believe the speed difference would be minimal. I've done some benchmarks and the speed difference between str_replace() and preg_replace() is only about 1/2 second in across 100000 executions (5 replaces per instance). Another .6 of a second is added when preg_replace() is used with 'i' flag which makes it case insensitive. I have not benchmarked the stri_replace code but I imagine it would be in the same ballpark, meaning that we are adding a fairly large chunk of code for performance benefit of a 1 microsecond (1 millionth of a second) per instance.

Ilia

What's the benchmark code? How is the benchmark difference on large text (ie. 100K of text) vs. small text (1K or smaller)?

Shane


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to