A class that tests the php program running time
- Class runTime {
- Private $ starTime; // start time
- Private $ stopTime; // end time
- Private function getMicTime (){
- $ Mictime = microtime (); // Obtain the timestamp and number of microseconds
- List ($ usec, $ sec) = explode ("", $ mictime); // splits the number of microseconds into an array and converts it to a variable for processing.
- Return (float) $ usec + (float) $ sec; // forces the converted data to be processed by float points.
- }
- Public function star () {// Obtain the start time
- $ This-> starTime = $ this-> getMicTime ();
- }
- Public function stop () {// Obtain the end time
- $ This-> stopTime = $ this-> getMicTime ();
- }
- Public function spent () {// computing program duration
- Return round ($ this-> stopTime-$ this-> starTime) * 1000; // get the number of milliseconds
- }
- }
- // Example
- $ Time = new runTime ();
- $ Time-> star ();
- For ($ I = 1; $ I <= 1000; $ I ++ ){
- Echo ("");
- }
- $ Time-> stop ();
- Echo $ time-> spent ();
- ?>
|