PHP String Manipulation Performance Benchmarking

Posted by Chad

Believe it or not, but I’ve been off the Rails for a couple months now. I went back to PHP because of the speed issues with Rails (and Ruby in general). As I mentioned, video.conductr was so slow on Rails I had to rewrite the whole thing in PHP. It wasn’t that bad, it’s a dead simple application. But, that’s what got me working with PHP again – and I love the speed.

Now I’ve started working on a new project that is quite large. I learned a lot about OOP from using Ruby which has made coming back to PHP tolerable being that it now has better support for objects. (I jumped ship sometime before PHP5).

Anyways, the point of writing this article is because I always refactor my code for performance. My refactoring process often includes looking for double quotes which can be single quotes, rethinking my functions, loops, and a whole bunch of string manipulations. But, as I was refactoring I start to wonder what kind of gains I was receiving or whether they were even worth my time.

To further spark my curiosity, I ran accross these tips today courtesy of DZone. So, I decided to write up a little benchmarking script to see how much difference my refactoring has on overall performance.

Benchmarking PHP String Manipulations

After refreshing the page a few times it’s easy to see that the performance advantages are so small that they are not even consistent. The typical performance gain is a few tenths of a second per 100,000 executions.

Comments

Leave a response

  1. JaisenMarch 03, 2008 @ 09:24 AM

    Chad, Thanks for benchmarking. Some are definitely negligible…but still good programming practice once you think about what PHP actually does with the code. I linked to this post from the original article.