Question about the microtime () function

Source: Internet
Author: User
About the microtime () function, I used the microtime () function to get the current time at the beginning and end of the program, and then subtract the program running time. There is no problem in php 5.2, however, in versions 5.3, 5.4, and 5.5, the result of the php subtraction is either 0 or 0.0156, which is completely different from that in version 5.2.6. what is the problem?


Reply to discussion (solution)

Paste your code

$ StartTime = microtime (true); printf ("%. 53f", microtime (true)-$ startTime );


For example, in the two sentences, a value is output every time in Version 5.2, but in other versions, all the values are 0.

$ StartTime = microtime (true); for ($ I = 0; $ I <1000000; $ I ++) {$ a = 1;} printf ("%. 16f ", microtime (true)-$ startTime );
0.0468750000000000

This is the power of the version.
You can change the final value of the loop so that all versions have output
Then you will find that every time you increase a version number, the time will be reduced by at least one order of magnitude.

The running time of different versions is normal.
The higher version is optimized than the lower version. of course, the time is much less.

Thank you for learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.