WordPress enables you to precisely plan out your content

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

| 2 Comments

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.

Categories: Code & Snippets | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Let a WordPress Expert help you

Do you want to try this, but feel like you need a helping hand, in case something goes wrong? My service, The WP Butler, gives you access to WordPress expertise whenever you need it. Better yet, I'll keep your site backed up, updated and secure, so that you don't have to worry about it. It's all part of the service. Use coupon DIWW and save 15% on all plans.

Visit The WP Butler

Author:

Dave has been tinkering with WordPress for many years, and he now shares his WordPress knowledge here on Do It WIth WordPress to help others realise its impressive power. He can also be hired to help with your WordPress needs. Dave, who is British, is married to his best friend, Marti, with whom he has a beautiful daughter, Ellie. When he's not dabbling with WordPress, he's probably eating Triscuits or hummus, watching an indie film or British TV show, spending time with friends or family, or exploring the world.

2 Comments

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

Leave a Reply