Copy CodeThe code is 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 bit of a try, you can find this code has a serious problem. Although T2 get more time than T1, but does not mean that its microsecond number is certainly greater than the number of microseconds T1. So if you subtract directly, the MS section is likely to get negative numbers. So, I changed a little bit myself, the code is as follows:
Copy CodeThe code is as follows:
$t 1 = microtime (true);
// ... Execute code ...
$t 2 = Microtime (true);
Echo ' time-consuming '. Round ($t 2-$t 1,3). ' Seconds ';
Simply say it. Microtime () If a true argument is taken, the return will be a floating-point type. So t1 and T2 get is two floating point number, subtract and get the difference between. Because the number of bits in the floating point is very long, or is not sure, then use a round () to remove the decimal point 3 bits. So our purpose is to reach the ~
http://www.bkjia.com/PHPjc/323343.html www.bkjia.com true http://www.bkjia.com/PHPjc/323343.html techarticle Copy the 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 try ...