Skip to content

Instantly share code, notes, and snippets.

@marekdedic
Created June 17, 2018 20:50
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 marekdedic/dac20c11d8fe1636c300f9c188d970c0 to your computer and use it in GitHub Desktop.
Save marekdedic/dac20c11d8fe1636c300f9c188d970c0 to your computer and use it in GitHub Desktop.
PHP Profiling functions
// Call this at each point of interest, passing a descriptive string
function prof_flag($str)
{
global $prof, $prof_last, $prof_last_value;
if(!isset($prof_last_value))
{
$prof_last_value = 0;
}
if(isset($prof_last))
{
if(!isset($prof[$prof_last]))
{
$prof[$prof_last] = 0;
}
$prof[$prof_last] += microtime(true) - $prof_last_value;
}
$prof_last = $str;
$prof_last_value = microtime(true);
}
// Call this when you're done and want to see the results
function prof_sprint()
{
$ret = '';
global $prof;
foreach($prof as $str => $value)
{
$ret .= '<b>' . $str . '</b><br>';
$ret .= sprintf('&nbsp;&nbsp;&nbsp;%f<br>', $value);
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment