Lots of people overclock their PCs, and more and more these days are augmenting their cars to make them perform better too. Well, there's a growing movement in the PHP community to want to squeeze just as much speed out of a PHP script as possible. These people obsess over whether a regular expressions are faster than a simple string replacement, or if they should use output buffering in their script just to help compress it.
Well, PHPEverywhere has a comparison just for all of you out there that think lean, mean, and clean code is everything. On their main page, they compare several of the string related functions, and the response time of each (in seconds). He did the tests on a pretty powerful machine (800mhz win2k) and just ran the same command 500 times in a row and got the amount of time that it took. The results aren't really all that surprising for anyone that's worked with PHP for a long time now.
So, the speedy way to search text is strpos, strstr (slower because of the overhead of returning a string rather than a number), followed by preg_match and in last place ereg. It appears that the preg_match function compiles and caches the compiled regular expressions, while ereg doesn't cache the compiled regular expressions, so every call to ereg in this benchmark requires a s-l-o-w recompilation.
The regular expressions take longer than the regular string functions, but that's a good trade off for the power that they provide.




