Copy codeThe Code is as follows:
$ T1 = explode ('', microtime ());
//... Execute the code...
$ T2 = explode ('', microtime ());
Echo ($ t2 [1]-$ t1 [1]). 'S '. ($ t2 [0]-$ t1 [0]). 'ms ';
In fact, you can find this code has a serious problem. although the time obtained by t2 is certainly greater than that obtained by t1, it does not mean that the number of microseconds must be greater than that of t1. so directly subtract, The MS part may get a negative number. therefore, I made a slight change and the code is as follows:
Copy codeThe Code is as follows:
$ T1 = microtime (true );
//... Execute the code...
$ T2 = microtime (true );
Echo 'elapsed time'. round ($ t2-$ t1, 3). 'second ';
To put it simply. microtime () if it contains a true parameter, a floating point type is returned. in this way, t1 and t2 get two floating point numbers, and the difference is obtained after subtraction. because the number of floating point digits is very long or uncertain, we can use a round () to retrieve the three digits after the decimal point. in this way, our goal is achieved ~