Last active
April 13, 2016 14:03
-
-
Save CraigChilds94/cdd43159d3eac24952967b8ed3f9fd21 to your computer and use it in GitHub Desktop.
Work out time taken to run a block, give it a nice name/label and output a nice message.
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
<?php | |
/** | |
* Work out time taken to run a block, give it a nice name/label | |
* and output a nice message. | |
* | |
* @param string $name | |
* @param callable $call | |
* @return mixed | |
*/ | |
function time_taken($name = 'Function call ', $call) | |
{ | |
$start = microtime(true); | |
$return = $call(); | |
$total = microtime(true) - $start; | |
echo PHP_EOL . $name . ' took ' . $total . ' seconds' . PHP_EOL; | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment