Last active
July 17, 2020 14:46
-
-
Save lfbn/b16a65c72685df33026ff77549731618 to your computer and use it in GitHub Desktop.
[[php] Time profiling a PHP script] #performance
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
// 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(" %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