CODE: Down And Dirty Page Page Timing In PHP
Thanks for visiting! We would like to serve you better. Please subscribe to our RSS feed for daily updates. This blog posts regular Wordpress news, updates of themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. You can also receive updates from this blog via email if you want that method of notification.
There are times when you’re working on a project and you need to test a page’s load
overhead. For instance, if you have a lot of database calls or are using some crazy regex
kung fu. These two little snippets of PHP code will give you a start to finish execution time
of the page you’re loading up. Put the first one at the very top and the second one at the
very bottom and load it up. When the page is finished rendering, just view source and you
can see the execution time in the HTML comment. You can remove the comment if you
want it to echo straight to your page. If you leave it in the comments, you can deploy this
in a production page and monitor the load times whenever you feel like it.
This goes at the top:
<?php
ereg(”(\.[0-9]+) ([0-9]+)”,microtime(),$time);
$starttime = doubleval($time[1])+doubleval($time[2]);
?>
This goes at the end:
<?php
ereg(”(\.[0-9]*) ([0-9]*)”,microtime(),$time);
$endtime=doubleval($time[1])+doubleval($time[2]);
$runtime = number_format($endtime-$starttime,4).” Seconds”;
echo “<!– [$runtime] –>”;
?>
There ya have it! [Jason]
…excerpt from: http://channels.lockergnome.com/web/backissues/20040324.phtml#20040324_2














Comments RSS
That’s actually a pretty bad way to do it. ereg? Useless. Check out timer_start and timer_stop in WP.
[Reply] Matt (64 comments.) — 04/1/2004 @ 5:40 pmWhy not get assign the microtime at the start of a script to a temporary variable, then subtract it from the microtime at the end of the script? It’s much cleaner.
[Reply] Desi Quintans (1 comments.) — 12/6/2005 @ 1:48 am