Home >Backend Development >PHP Tutorial >PHP code running time view class code sharing

PHP code running time view class code sharing

高洛峰
高洛峰Original
2016-11-30 11:19:301037browse

The code is as follows:
//date:2011-08-05
class RunTime//Page execution time class
{
private $starttime;//Page start execution time
private $stoptime;//Page end execution time
private $ spendtime;//The time it takes to execute the page
function getmicrotime()//Get the floating point number that returns the current microsecond
{
list($usec,$sec)=explode(" ",microtime());
return ((( float)$usec + (float)$sec);
}
function start()//The page starts executing the function and returns the time when the page starts executing
{
$this->starttime=$this->getmicrotime() ;
}
function end()//Display the page execution time
{
$this->stoptime=$this->getmicrotime();
$this->spendtime=$this->stoptime-$ this->starttime;
//return round($this->spendtime,10);
}
function display()
{
//$this->end();
echo "

Running time: ".round($this->spendtime,10)."Seconds

";
}
}
/*Call method
$timer=new Runtime();
$timer-> start();

Statement:
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