How to Calculate PHP Load Times
Here’s a popular request amongst those who are learning PHP. When developing PHP applications, it’s good practice to benchmark your pages to see if you need to further optimize your code. The following snippet will show you how much time it took your server to process your PHP document.
Insert this at or near the top of your PHP file.
Now place this snippet at or near the bottom of your file for the best results.
That’s it! I suggest adding this while you develop any PHP application, and include it even after the launch, so that you can see how well your scripts scale with the traffic you receive.

If you click the link in my name, that is the timer function I always use to calculate. Makes it really nice and easy!
Comment by Adam — January 4, 2008 @ 4:44 pm
This is terrific. I am using a shared hosting plan and a few weeks ago, my CPU was overloading like crazy so I had to disable some plugins to settle things back to normal.
Can I do this with exsisting plugins to see which one is causing overload issues?
Comment by Mark @ TheLocoMono — January 26, 2008 @ 3:43 pm
I’ve re-factored this so it’s much smaller:
top of page:
$load_start = array_sum(explode(” “, microtime()));
bottom of page:
$load_end = array_sum(explode(” “, microtime()));
echo “Page generated in “.number_format($load_end - $load_start, 5).” seconds”;
Comment by Ron — April 23, 2008 @ 7:39 pm
Nice code snip!
Comment by Johnson — May 13, 2008 @ 8:24 pm
Thanks for those functions Adam - will come in handy
Comment by Stefan Ashwell — September 1, 2008 @ 7:39 am
Even though I see the benefits of this method, as it is so simple, this kind of benchmarking is unlikely to help you find the true bottlenecks in your application. It merely measure the speed of every page and require a lot more effort to pinpoint the slow code. Also, focusing on decreasing the speed of a page does not mean it will be able to scale properly to a large number of users, so it is best to focus on scalability rather than pure speed.
I would suggest to use a tool like XDebug (http://www.xdebug.org/) that will profile your code from within PHP (without cluttering your code) and outputs a file with a tremendous amount of details. You can find the bottlenecks of your application within minutes.
Comment by Remi — April 3, 2009 @ 12:00 pm