Created
November 10, 2015 20:33
-
-
Save hattmarris/f70c92c8855162c846be to your computer and use it in GitHub Desktop.
PHP Time
This file contains hidden or 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
<?php | |
/** | |
* Time difference logging function | |
* | |
* $start time from PHP microtime(true) // returns seconds as float | |
* $end time from PHP microtime(true) | |
*/ | |
function logTimeDiff($start, $end) { | |
$seconds = $end - $start; | |
$milli = $seconds / 1000; | |
return $milli . 'ms, ' . $seconds . 'sec' . PHP_EOL; | |
} | |
function testLogTimeDiff($microseconds) { | |
$a = microtime(true); | |
usleep($microseconds); | |
echo logTimeDiff($a, microtime(true)); | |
} | |
testLogTimeDiff(2000000); // wait for 2 seconds | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment