Home > Backend Development > PHP Tutorial > A class for testing the running time of php programs

A class for testing the running time of php programs

WBOY
Release: 2016-07-25 09:03:31
Original
855 people have browsed it
  1. class runTime {
  2. private $starTime;//Start time
  3. private $stopTime;//End time
  4. private function getMicTime(){
  5. $mictime=microtime();//Get time Stamp and microseconds
  6. list($usec,$sec)=explode(" ",$mictime);//Split the microseconds into arrays and convert them into variables for processing
  7. return (float)$usec+(float)$sec ;//Force the converted data to be processed with floating point points
  8. }
  9. public function star(){//Get the start time
  10. $this->starTime=$this->getMicTime();
  11. }
  12. public function stop(){//Get the end time
  13. $this->stopTime=$this->getMicTime();
  14. }
  15. public function spent(){//Calculate the 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("a");
  24. }
  25. $time->stop();
  26. echo $time->spent();
  27. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template