Performance tuning

Posted by Jim Jagielski on Monday, November 20. 2006 in Programming

While checking out a suggested patch for Telaen, I noticed a lot of places where the code does a regex check instead of a more simple string comparison. This is done when checking for the response back from the POP3 server and is looking for a response that starts with '+OK'. Using 'ereg' (Telaen is written in PHP) seemed overkill to me, plus I made the assumption that doing a simple 'substr' and comparison would be faster as well. But would it? Since this check is only done after sending the POP3 server a command, it's done pretty rarely, most of the time spent is in disk and network I/O. I did some profiling and, in typical cases, the difference was pretty much in-the-noise, but in cases with lots of small Email messages, there really was a small but noticable difference. Of course, even so, if the "faster" code wasn't any clearer, then I doubt I would even have made the change... but, IMO, this change did make the code more easily read, but mostly due to that nasty little '+' in there, which could trip people up in the regex. Kernighan and Pike are right.

The author does not allow comments to this entry


Search for an entry in IMO:

Did not find what you were looking for? Post a comment for an entry or contact us via email!