Calculating PHP script execution time in seconds

microtime(true) with the parameter true will return a float number in seconds, the number of seconds has passed since the Unix epoch (0:00:00 January 1,1970 GMT). Call this function before and after a code snippet, and the differences of the two float numbers is the running time for that code snippet in seconds.

$start_time = microtime(true);

for($i=0; $i<100000; $i++)
	echo $i;

$end_time = microtime(true);
echo "\n Start time: $start_time\n End Time: $end_time\n";
$executionTime = $end_time - $start_time;
echo "\n Time taken: $executionTime seconds.\n";

Search within Codexpedia

Custom Search

Search the entire web

Custom Search