Diagnosing sticking points in your page load time with timer_stop()

WordPress enables you to precisely plan out your content

This is a quick little tip to help you find points in your page load that are taking the longest, so that you can help find what may be causing them.

There’s a function in WordPress called timer_stop() and it takes a snapshot of how long the page has taken to load up until the point the function is called.

The timer starts when the page starts loading and you can then use this function at various strategic locations in your theme files to so how long it takes to load to each point.

You might choose to put one at the end of your head section, one before the loop, one after the loop, one before the footer and one after the footer for example.

Once you see the results, you might iterate and insert more timers in the section which is taking the longest to load. The timer doesn’t reset every time you use it, so you’ll be looking for the section with the biggest difference between timer values.

The timer_stop function takes two parameters: display and precision. Display dictates whether to display the result (1) or use it in PHP (0) and the precision says to how many decimal places you want the time (3 would return a result of x.xxx seconds).

To use the timer, I recommend inserting it as a comment in your HTML. Once you’ve located the points in your theme files, you can paste the following code wherever you want a timer:

Then, when you reload your page and view the source code, you’ll see an HTML comment, like this:

Using timer_stop

Once you’re done diagnosing the issue, be sure to remove the timers from your theme files.

2 thoughts on “Diagnosing sticking points in your page load time with timer_stop()”

  1. Top tip Dave, wouldn’t have thought to put that in a comment – nice!

    1. I was originally shown that by Mark Jaquith at last year’s Orlando WordCamp ;)

Leave a Reply