Created
January 23, 2019 17:52
-
-
Save fmtarif/664e0e64e2958daba9dbab6a026faecb to your computer and use it in GitHub Desktop.
#php execution profiling, get elapsed time
This file contains hidden or 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
<?php | |
function get_execution_time() | |
{ | |
static $microtime_start = null; | |
if($microtime_start === null) | |
{ | |
$microtime_start = microtime(true); | |
return 0.0; | |
} | |
return microtime(true) - $microtime_start; | |
} | |
function get_execution_time_alt() { | |
return microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; | |
} | |
//usage | |
get_execution_time(); | |
sleep(2); | |
echo 'elapsed time ' . get_execution_time() . ' seconds'; | |
//usage | |
sleep(1); | |
echo 'elapsed time ' . get_execution_time_alt() . ' seconds'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment