note 63391 deleted from function.microtime by tularis

From: Date: Sun, 22 Jun 2008 12:11:15 +0000
Subject: note 63391 deleted from function.microtime by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140686@lists.php.net to get a copy of this message
Note Submitter: webmaster [AT] dtronix [DOT] com ---- Here is a small script I made so that I would not have to deal with vars. All you have to do is run the function twice and the second time run, it will echo the runtime. If you place a number in the last function "script_runtime(5)" it will round off the number to that decimal place. <?php function script_runtime ( $round = 20 ) { //Check to see if the global is already set if ( !empty( $GLOBALS['start_script_runtime'] ) ) { //The global was set. So, get the current microtime and explode it into an array. list($msec, $sec) = explode(" ", microtime()); echo round(($sec + $msec) - $GLOBALS['start_script_runtime'], $round); } else { // The global was not set. Create it! list($msec, $sec) = explode(" ", microtime()); $GLOBALS['start_script_runtime'] = $sec + $msec; } } // Example: script_runtime(); sleep(1); script_runtime(); ?>

« previous php.notes (#140686) next »