note 24712 deleted from function.microtime by aidan

From: Date: Tue, 28 Sep 2004 12:08:00 +0000
Subject: note 24712 deleted from function.microtime by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77480@lists.php.net to get a copy of this message
Note Submitter: su-php at bossi dot com ---- 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.

« previous php.notes (#77480) next »