Copy Code code as follows:
$t 1 = Explode (', microtime ());
// ... Execute code ...
$t 2 = Explode (', microtime ());
Echo ($t 2[1]-$t 1[1]). ' S '. ($t 2[0]-$t 1[0]). ' Ms ';
In fact, a little trial, you can find that the code has a serious problem. Although T2 time is certainly larger than T1, but does not mean that its microseconds must be more than the number of T1 microseconds. So if you subtract directly, the MS part is likely to get a negative number. So I changed it myself a little bit, and the code was as follows:
Copy Code code as follows:
$t 1 = microtime (true);
// ... Execute code ...
$t 2 = Microtime (true);
Echo ' time consuming '. Round ($t 2-$t 1,3). ' Seconds ';
Simply say. Microtime () returns a floating-point type if with a true argument. So t1 and T2 get two floating-point numbers and subtract the difference between them. Because the number of floating-point digits is very long or uncertain, use a round () to remove 3 digits from the decimal point. So our goal is reached