Front-End PHP entry -023-program execution time detection for key date functions

Source: Internet
Author: User

We often need to do the execution time execution efficiency judgment of the program.

The following ideas are implemented:

 
   
  
  1. <?php
  2. //记录开始时间
  3. //记录结整时
  4. // 开始时间 减去(-) 结束时间 得到程序的运行时间
  5. ?>

But let's not forget that the program is running too fast. It's just 0.00000 seconds to the flash. At this point, we're going to write a function of a special letter:

Mixed Microtime ([bool $get _as_float])

The Microtime () function, which returns the current Unix timestamp and the number of microseconds.

Parameters:
If you pass in true, it will return a floating-point type of time, so that it is convenient to participate in the operation.

Let's simulate an example that detects the execution time of a function and tests how quickly a function is efficient:

  
 
  1. <?php
  2. //开始时间
  3. $time_start = microtime(true);
  4. //循环一万次
  5. for($i = 0 ; $i < 10000 ; $i++){
  6. //你可以用上,mktime() 生成一个昨天的时间
  7. //再用strtotime() 生成一个昨天的时间
  8. //对比两个函数认的效率高
  9. }
  10. //结整时间
  11. $time_end = microtime(true);
  12. //相减得到运行时间
  13. $time = $time_end - $time_start;
  14. echo "这个脚本执行的时间为 $time seconds\n";
  15. ?>


From for notes (Wiz)

Front-End PHP entry -023-program execution time detection for key date functions

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.