Home / code

Time script

Writer: Christophe Wolfs
Published: 27 March 2008

This is a script that measures the time that takes to executes a script.
There are 2 parts, you place the first on top of your page.
The second at the bottom of your page.

<?php
/*start of the first part*/
function getmicrotime()
{  
 list($usec, $sec) = explode(" ",microtime());  
 return ((float)$usec + (float)$sec);  
}  
$time_start = getmicrotime();  

/*Here you start your script*/
for($i=0; $i < 1000; $i++){  
}  
/*Here you end your script*/
/*Start of the second part*/

$time_end = getmicrotime();  
$time = $time_end - $time_start;  
$time = round($time,5);  
echo "Page loaded in : $time seconds.";
?>

 

TOP