Code snippet: Getting PHP page generation time

This is a code snippet on how to get the execution time of a PHP script.
This is the first from the code snippet series.

<?php 

function GetMicroTime() 
{
        list($microseconds, $seconds) = explode(" ", microtime());     
        return ((float)$microseconds + (float)$seconds); 
} 

//read the time at the beggining of the php file 
$nStartTime = GetMicroTime(); 

/* Your code goes here  
... 
*/ 

//read the time at the end of the php file 
$nEndTime = GetMicroTime(); 
$szGeneratedTime = "Page generated in " . 
                    number_format(($nEndTime - $nStartTime), 4) . 
                    " seconds."; 
echo $szGeneratedTime; 
?>

vultr banner
VN:F [1.9.11_1134]
Rating: 8.7/10 (9 votes cast)
Code snippet: Getting PHP page generation time, 8.7 out of 10 based on 9 ratings