Many times we need to calculate the execution time of the PHP script to learn about the efficiency of the script, and so on. For example, there is a large section of PHP script, we need a fragment to get the script execution time method. First introduce the function to be used:
Timing functions
function runtime ($mode = 0) {
Static $t;
if (! $mode) {
$t = Microtime ();
Return
}
$t 1 = microtime ();
List ($m 0, $s 0) = Split ("", $t);
List ($m 1, $s 1) = Split ("", $t 1);
Return sprintf ("%.3f MS", ($s 1+ $m 1-$s 0-$m 0) *1000);
}
Runtime (); Timing starts
/*
PHP script to calculate
$result = 0;
for ($i = 0; $i < $i + +) {$result + = $i;} echo $result; */Echo runtime (1); Timing end and output timing result runtime (); Timing Start/*//php script to be calculated $result = 0; for ($i = 0; $i < $i + +) {$result + = $i;} echo $result; */Echo runtime (2); Timing end and output timing results
Microtime () function
The Microtime () function returns the current Unix timestamp and the number of microseconds.
Microtime (get_as_float), parameter get_as_float, if the get_as_float parameter is given and its value is equivalent to TRUE, the function returns a floating-point number.
<?php
Echo (Microtime ());
?>
If called without optional arguments, this function returns a string in the format "msec sec", where the SEC is the number of seconds since the Unix era (0:00:00 January 1, 1970 GMT) and msec is the microsecond portion. The two parts of a string are returned in seconds.
Program output:
0.25139300 1138197510
Now it's time to compute the timephased execution of the PHP script.
Segment to calculate execution time for PHP scripts