PHP code execution time-consuming code fixes common online errors. Copy the code as follows: $ t1explode (, microtime ());... run the code... $ t2explode (, microtime (); echo ($ t2 [1]-$ t1 [1]). s. ($ t2 [0]-$ t1 [0]). ms; in fact, try it a little
The 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:
The 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 ~
The http://www.bkjia.com/PHPjc/323343.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323343.htmlTechArticle code is as follows: $ t1 = explode ('', microtime ());//... run the code... $ t2 = explode ('', microtime (); echo ($ t2 [1]-$ t1 [1]).'s '. ($ t2 [0]-$ t1 [0]). 'Ms'; in fact, try it a little...