Skip to content

Instantly share code, notes, and snippets.

@CraigChilds94
Last active April 13, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigChilds94/cdd43159d3eac24952967b8ed3f9fd21 to your computer and use it in GitHub Desktop.
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.
<?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