Created
March 27, 2012 09:41
-
-
Save nyson/2214421 to your computer and use it in GitHub Desktop.
Short snippet to evaluate execution time from a function in php
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
<? | |
/** | |
* Gets execution time of a closure (Anonymous Function) | |
* | |
* @param $action Closure to execute | |
* @param $return [optional] Pass reference to recieve return values | |
* | |
* @return execution time of the closure in seconds in float | |
*/ | |
function getExecutionTime(Closure $action, &$return=null){ | |
$mtime = microtime(true); | |
$return = $action(); | |
return microtime(true) - $mtime; | |
} | |
/***~~~... EXAMPLE ...~~~***/ | |
$test = function (){ | |
// test code here | |
}; | |
echo "Code executed in " . getExecutionTime($test) . " ms!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment