note 24712 added to function.microtime
| From: | su-php at bossi dot com | Date: | Mon, 26 Aug 2002 21:18:20 +0000 |
| Subject: | note 24712 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35688@lists.php.net to get a copy of this message | ||
If you want a running display of how long each function takes in your app, then use the following:
function echo_stopwatch()
{
global $stop_watch;
echo "\n\n<!--\n";
echo "\nTiming ***************************************************\n";
$total_elapsed = 0;
list($usec, $sec) = explode(" ",$stop_watch['Start']);
$t_end = ((float)$usec + (float)$sec);
foreach( $stop_watch as $key => $value )
{
list($usec, $sec) = explode(" ",$value);
$t_start = ((float)$usec + (float)$sec);
$elpased = abs($t_end - $t_start);
$total_elapsed += $elpased;
echo( str_pad($key, 20, ' ', STR_PAD_LEFT).":
".number_format($elpased,3).' '.number_format($total_elapsed,3), 0 )."\n";
$t_end = $t_start;
}
echo "\n";
echo( str_pad("Elapsed time", 20, ' ', STR_PAD_LEFT).":
".number_format($total_elapsed,3), 0 )."\n";
echo "\n-->";
}
Then wherever you want to have a "lap" time, simply use the line:
$stop_watch['DB Connect'] = microtime();
and
$stop_watch['Included VAR File'] = microtime();
and
$stop_watch['Retrieve Stats'] = microtime();
and so on. Then at the end of your app:
echo_stopwatch();
And you can view the HTML source.
Be sure to use UNIQUE names, otherwise the previous value will be replaced by the new value.
--
http://www.php.net/manual/en/function.microtime.php
http://master.php.net/manage/user-notes.php?action=edit+24712
http://master.php.net/manage/user-notes.php?action=delete+24712
http://master.php.net/manage/user-notes.php?action=reject+24712