A class that tests the php program running time

Source: Internet
Author: User
A class that tests the php program running time

  1. Class runTime {
  2. Private $ starTime; // start time
  3. Private $ stopTime; // end time
  4. Private function getMicTime (){
  5. $ Mictime = microtime (); // Obtain the timestamp and number of microseconds
  6. List ($ usec, $ sec) = explode ("", $ mictime); // splits the number of microseconds into an array and converts it to a variable for processing.
  7. Return (float) $ usec + (float) $ sec; // forces the converted data to be processed by float points.
  8. }
  9. Public function star () {// Obtain the start time
  10. $ This-> starTime = $ this-> getMicTime ();
  11. }
  12. Public function stop () {// Obtain the end time
  13. $ This-> stopTime = $ this-> getMicTime ();
  14. }
  15. Public function spent () {// computing program duration
  16. Return round ($ this-> stopTime-$ this-> starTime) * 1000; // get the number of milliseconds
  17. }
  18. }
  19. // Example
  20. $ Time = new runTime ();
  21. $ Time-> star ();
  22. For ($ I = 1; $ I <= 1000; $ I ++ ){
  23. Echo ("");
  24. }
  25. $ Time-> stop ();
  26. Echo $ time-> spent ();
  27. ?>

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.