Created
June 17, 2018 20:50
-
-
Save marekdedic/dac20c11d8fe1636c300f9c188d970c0 to your computer and use it in GitHub Desktop.
PHP Profiling functions
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
// 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(' %f<br>', $value); | |
} | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment