A PHP class that calculates the program run time

Source: Internet
Author: User
  1. /**
  2. * Calculate program Run time
  3. * filename:js_runtime.php
  4. */
  5. Class Timer {
  6. Private $StartTime = 0;//program run start time
  7. Private $StopTime = 0;//program Run end time
  8. Private $TimeSpent = 0;//program takes time to run
  9. function Start () {//program run start
  10. $this->starttime = Microtime ();
  11. }
  12. function Stop () {//program run end
  13. $this->stoptime = Microtime ();
  14. }
  15. function spent () {//time spent by program run
  16. if ($this->timespent) {
  17. return $this->timespent;
  18. } else {
  19. List ($StartMicro, $StartSecond) = Explode ("", $this->starttime);
  20. List ($StopMicro, $StopSecond) = Explode ("", $this->stoptime);
  21. $start = Doubleval ($StartMicro) + $StartSecond;
  22. $stop = Doubleval ($StopMicro) + $StopSecond;
  23. $this->timespent = $stop-$start;
  24. Return substr ($this->timespent,0,8). " Seconds ";//returns the program run time difference that gets to
  25. }
  26. }
  27. }
  28. $timer = new timer ();
  29. $timer->start ();
  30. //... Code to run the program
  31. $timer->stop ();
  32. echo "Program run Time:". $timer->spent ();
  33. ?>
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.