A few days ago, when I tested SQLite to insert a large amount of data, I found some code about the computing execution time, and found that such a piece of code is circulating on the Internet.
A few days ago, when I tested SQLite to insert a large amount of data, I found some code about the computing execution time, and found that such a piece of code is circulating on the Internet.
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 ~