Tue, Dec 20, 2005, 9:13pm Optimization I: not preg_replace()
Blogging » Making This Blog
(Last updated: Thu, Jan 5, 2006, 4:20am)
added in some timers in the debug routines behind the scenes to find out where the biggest time wasters are in the code. My first guess was the large amount of preg_replace() calls which happens many times per page draw. I thought that preg_replace() probably already identifies replacements which are not regular expressions and that swapping those lines out for str_replace() probably wouldn't save much time, but I wanted to actually see if this was true.

I picked 3 pages and reloaded them several times to find roughly their load times. The front page takes about 103 milliseconds to load; the status page, which has several comments in the forum making use of bbcode, takes about 140 to 160ms; and an example blog page takes between 30 to 40ms. After the trial optimization, there was no discernible change in load times, showing that preg_replace() is smart enough to separate things out internally on its own. Sometimes it's just best to verify such things.

Then I was wondering what page renderings would look like with no string substitutions at all (thought this trashes the actual html output), and found these averages: index 85ms, status 109ms, blog post 22ms. So that function must be taking up between 10-40ms to do its stuff. So, not nothing, but not yet a big deal.

This is all just temporary curiosity stuff here. I want to build in analysis tools to the basic page objects to make generating real statistics on pages or functions trivial, even over the web. But all this only took a few minutes. Took longer to write this note about it up.

  • John Bachir (Tue, December 20th, 2005, 10:09pm UTC)
    Interesting stuff. It would be nice to somehow do all the pregreplace stuff "all at once"… without making multiple passes.

Leave a comment