Copy codeThe Code is as follows:
<? Php
List ($ usec, $ sec) = explode ('', microtime ());
$ Timer = (float) $ usec + (float) $ sec;
Mysql_query ($ query, $ active_db );
List ($ usec, $ sec) = explode ('', microtime ());
$ Stop = (float) $ usec + (float) $ sec;
$ Diff = $ stop-$ timer;
?>
$ Stop and $ timer are converted floating point numbers. In most cases, the results obtained by echo $ stop and echo $ timer are the same with the naked eye, however, they are stored in different computers, so the result is not 0 or negative.
The php manual prompts:
Floating Point precision:
Obviously, a simple decimal score is like 0.1 or 0.7. It cannot be converted to an internal binary format without losing a little precision. This will lead to chaotic results: for example, floor (0.1 + 0.7) * 10) usually returns 7 instead of 8 in expectation, because the internal representation of the result is similar to 7. 9999999999 ....
This is related to the fact that it is impossible to accurately express certain decimal scores with limited digits. For example, decimal 1/3 is changed to 0.3333333 ....
Therefore, never believe that the result of a floating point number is accurate to the last digit, or compare whether the two floating points are equal. If higher precision is required, use any precision mathematical function or gmp function.