Skip to content

Instantly share code, notes, and snippets.

@fmtarif
Created January 23, 2019 17:52
Show Gist options
  • Save fmtarif/664e0e64e2958daba9dbab6a026faecb to your computer and use it in GitHub Desktop.
Save fmtarif/664e0e64e2958daba9dbab6a026faecb to your computer and use it in GitHub Desktop.
#php execution profiling, get elapsed time
<?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