Forum Moderators: coopster
Basically, a calculation will occur when the submit button is pressed on Page 1. The result of this calculation will appear on Page 2. I would like to find out the amount of time it took for the computer to compute the calculation and thought that the best way to do this would be by seeing the amount of time to download the page. Maybe there is a better way of doing this anyway?
---
// beginning of script
$starttime = microtime();
//....do your stuff here....
// end of script
$endtime = microtime();
$parts_of_starttime = explode(' ', $starttime);
$starttime = $parts_of_starttime[0] + $parts_of_starttime[1];
$parts_of_endtime = explode(' ', $endtime);
$endtime = $parts_of_endtime[0] + $parts_of_endtime[1];
$time_taken = $endtime - $starttime;
$time_taken = number_format($time_taken, 2); // optional
print $time_taken;
---
noSanity
It will only measure the time it took PHP [php.net] to process the script. This can be done quite nicely using this function. It is functionally equivalent to nosanity´s code.
function getmicrotime($t) {
list [php.net]($usec, $sec) = explode [php.net](" ", $t);
return [php.net] ((float)$usec + (float)$sec);
}
#
$start = microtime() [php.net];
#
# Do your stuff here
#
$end = microtime() [php.net];
echo getmicrotime($end) - getmicrotime($start); Andreas