Skip to content

Instantly share code, notes, and snippets.

@lfbn
Last active July 17, 2020 14:46
Show Gist options
  • Save lfbn/b16a65c72685df33026ff77549731618 to your computer and use it in GitHub Desktop.
Save lfbn/b16a65c72685df33026ff77549731618 to your computer and use it in GitHub Desktop.
[[php] Time profiling a PHP script] #performance
// https://stackoverflow.com/a/29022400/155905
// Call this at each point of interest, passing a descriptive string
function prof_flag($str)
{
global $prof_timing, $prof_names;
$prof_timing[] = microtime(true);
$prof_names[] = $str;
}
// Call this when you're done and want to see the results
function prof_print()
{
global $prof_timing, $prof_names;
$size = count($prof_timing);
for($i=0;$i<$size - 1; $i++)
{
echo "<b>{$prof_names[$i]}</b><br>";
echo sprintf("&nbsp;&nbsp;&nbsp;%f<br>", $prof_timing[$i+1]-$prof_timing[$i]);
}
echo "<b>{$prof_names[$size-1]}</b><br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment