PHP test program running time class_PHP tutorial

WBOY
Release: 2016-07-21 15:20:50
Original
832 people have browsed it

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();
?>

www.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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!