Created
November 16, 2012 14:05
-
-
Save alloyking/4087592 to your computer and use it in GitHub Desktop.
Timed Database Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function StartTimer ($what='') { | |
global $MYTIMER; $MYTIMER=0; //global variable to store time | |
//if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') return; //only show for my IP address | |
echo '<p style="border:1px solid black; color: black; background: yellow;">'; | |
echo "About to run <i>$what</i>. "; flush(); //output this to the browser | |
//$MYTIMER = microtime (true); //in PHP5 you need only this line to get the time | |
list ($usec, $sec) = explode (' ', microtime()); | |
$MYTIMER = ((float) $usec + (float) $sec); //set the timer | |
} | |
function StopTimer() { | |
global $MYTIMER; if (!$MYTIMER) return; //no timer has been started | |
list ($usec, $sec) = explode (' ', microtime()); //get the current time | |
$MYTIMER = ((float) $usec + (float) $sec) - $MYTIMER; //the time taken in milliseconds | |
echo 'Took ' . number_format ($MYTIMER, 4) . ' seconds.</p>'; flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment