See the Class of PHP code run time

Source: Internet
Author: User
  1. /**

  2. * Function: Check the running time of PHP code
  3. * Date: 2012-12-29
  4. * File: show_php_runtime.php
  5. **/

  6. Class runtime//page Execution time classes

  7. {
  8. private $starttime;//page Start execution time
  9. private $stoptime;//page End Execution time
  10. private $spendtime;//page execution takes time
  11. function Getmicrotime ()//Gets the floating-point number that returns the current microsecond
  12. {
  13. List ($usec, $sec) =explode ("", Microtime ());
  14. return (float) $usec + (float) $sec);
  15. }
  16. function start ()//page to start the execution of functions, return to start Page execution time
  17. {
  18. $this->starttime= $this->getmicrotime ();
  19. }
  20. function end ()//Displays the time the page was executed
  21. {
  22. $this->stoptime= $this->getmicrotime ();
  23. $this->spendtime= $this->stoptime-$this->starttime;
  24. Return round ($this->spendtime,10);
  25. }
  26. function display ()
  27. {
  28. $this->end ();
  29. echo "

    Run time: ". Round ($this->spendtime,10)." Seconds

    ";
  30. }
  31. }

  32. /*

  33. Calling methods
  34. */
  35. $timer =new Runtime ();
  36. $timer->start ();
  37. ?>

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.