Hello
I would like to test how fast my PHP scripts are executed.
I was thinking of calculating the current time (if millis - if possible) at the beginning of the script (server side) and to send that value into a javascript variable.
When the page loads (onload() event), I calculate again the the current time in javascript and just subtract the latter from the first.
I am hoping that this will give me the time in millis from the moment the page reached the server until the time it was loaded in the client.
Does anyone know of a way to obtain the current time in millis?
Does anyone know of a better way to calculate performance?
thanks
measuring performance in PHP - how?
Moderator: General Moderators
-
davidklonski
- Forum Contributor
- Posts: 128
- Joined: Mon Mar 22, 2004 4:55 pm
i do it like this
Mark
Code: Select all
//put at begining of file
function utime (){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
$start = utime();Code: Select all
//put at end of page before /body and /h // tml tags
$end = utime();
$run = $end - $start;
echo "Page created in " . substr($run, 0, 5) . " secs.";-
davidklonski
- Forum Contributor
- Posts: 128
- Joined: Mon Mar 22, 2004 4:55 pm
If the microtime() functions returns the time in micro seconds in the form of "msec sec"
where sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and msec is the microseconds part. Both portions of the string are returned in units of seconds.
isn't there a way to get the number of Milliseconds since 0:00:00 January 1, 1970 GMT?
thanks
where sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and msec is the microseconds part. Both portions of the string are returned in units of seconds.
isn't there a way to get the number of Milliseconds since 0:00:00 January 1, 1970 GMT?
thanks
To get milliseconds from the epoch, just do
Code: Select all
time() * 1000Real programmers don't comment their code. If it was hard to write, it should be hard to understand.