A class that tests the run time of a PHP program

Source: Internet
Author: User
    1. !--? php class RunTime {
    2. private $starTime;//start time
    3. private $stopTime;//End
    4. Private Function Getmictime () {
    5. $mictime =microtime ();//get timestamp and number of microseconds
    6. list ($usec, $sec) = Explode ("", $mictime);//The number of microseconds divided into groups and converted to variable processing
    7. return (float) $usec + (float) $sec;//force the converted data with floating point to handle
    8. }
    9. Public Function Star () {//Get start time
    10. $this->startime= $this->getmictime ();
    11. }
    12. Public function Stop () {//Get end time
    13. $this->stoptime= $this->getmictime ();
    14. }
    15. Public function spent () {//Calculation program duration
    16. return round ($this->stoptime-$this->startime) *1000 ;//Gets the number of milliseconds
    17. }
    18. }
    19. //Example
    20. $time =new runTime ();
    21. $time->star ();
    22. for ($i =1; $i <=1000; $i + +) {
    23. echo ("a");
    24. }
    25. $time->stop ();
    26. echo $time->spent ();
    27. ?
Copy Code
  • 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.