Tuesday, 23 September 2014

Calculating execution time and memory usages in your php script

Here is the script snippet, by using this you can get the execution time of that script and memory usages:
Beginning of the script:

//place this before any script you want to calculate time
$time_start = microtime(true);


End of the script:

//Put it at the end of php script
$time_end = microtime(true);
$execution_time = round(($time_end - $time_start),5);
echo '<br><b>Total Execution Time:</b> '.$execution_time.' Sec';
echo '<br><b>Total Memory Usages:</b> '.round(memory_get_usage(true)/1024,2)." Kb";

No comments :

Post a Comment