Created
October 1, 2012 22:41
-
-
Save brianteachman/3814937 to your computer and use it in GitHub Desktop.
PHP timimg script using microtime() and BC Math
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
#!/usr/bin/php | |
<?php | |
$profile = function() { | |
static $start = '0'; | |
list($timestamp, $microseconds) = split(' ', microtime()); | |
$current = bcadd($timestamp, $microseconds, 4); | |
if ($start === '0') { | |
$start = $current; | |
return; | |
} | |
return bcsub($current, $start, 4); | |
}; | |
$profile(); | |
usleep(1000000); // 1 second | |
echo $profile() . ' seconds' . PHP_EOL; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is exactly what I was looking for. Thanks :)