Forum Moderators: coopster

Message Too Old, No Replies

How to time calculations

         

k8tie

4:24 pm on Mar 4, 2003 (gmt 0)

10+ Year Member



Hey
Does anyone have some script that times the amount of time it takes to bring up the next webpage from a link on the previous page?

jpjones

4:29 pm on Mar 4, 2003 (gmt 0)

10+ Year Member



By what criteria do you want to time?

1/ Time the time it takes for a visitor to access page 1 and then access page 2?

2/ Time the time it takes to download a page?

JP

k8tie

9:34 pm on Mar 4, 2003 (gmt 0)

10+ Year Member



The time it takes to download the page- I think!

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?

andreasfriedrich

10:28 pm on Mar 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To time a whole request cycle you will need to use either a script on the client or a benchmark tool such as Apache [httpd.apache.org]´s ab [httpd.apache.org]. I believe Microsoft has a free webserver benchmarking tool as well. Use the site search to look for that.

HTH Andreas

nosanity

9:12 pm on Mar 5, 2003 (gmt 0)

10+ Year Member



Try this...

---
// 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

andreasfriedrich

9:25 pm on Mar 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This will NOT measure the time it takes to download the page and it will NOT measure the time for a complete request cycle.

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