Skip to content

Instantly share code, notes, and snippets.

@hattmarris
Created November 10, 2015 20:33
Show Gist options
  • Save hattmarris/f70c92c8855162c846be to your computer and use it in GitHub Desktop.
Save hattmarris/f70c92c8855162c846be to your computer and use it in GitHub Desktop.
PHP Time
<?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