The class is very simple. It mainly uses several functions, the array list function list(), the string is divided into the array function explode(), and the timestamp and microsecond number microtime() are obtained. The code is as follows:
Copy code The code is as follows:
class runTime {
private $starTime;//Start time
private $ stopTime;//End time
private function getMicTime(){
$mictime=microtime();//Get timestamp and microseconds
list($usec,$sec)=explode(" " ,$mictime);//Split the microseconds into arrays and convert them into variables for processing
return (float)$usec+(float)$sec;//Force the converted data to be processed with floating point points
}
public function star(){//Get the start time
$this->starTime=$this->getMicTime();
}
public function stop(){//Get End time
$this->stopTime=$this->getMicTime();
}
public function spent(){//Calculate 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("a");
}
$time->stop() ;
echo $time->spent();
?>
http://www.bkjia.com/PHPjc/325012.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325012.htmlTechArticle class is very simple. It mainly uses several functions, the array list function list(), and the string is divided into array functions. explode(), get the timestamp and microseconds microtime(), the code is as follows: Copy the code...