Home  >  Article  >  Backend Development  >  Class code for calculating program running time in php_PHP tutorial

Class code for calculating program running time in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:15798browse

Copy code The code is as follows:

class Timer {
private $StartTime = 0;//Program running start time
private $StopTime = 0;//The end time of program running
private $TimeSpent = 0;//The time it takes to run the program
function start(){//The start of program running
$this->StartTime = microtime();
}
function stop(){//The program ends
$this->StopTime = microtime();
}
function spent(){//Program Time spent running
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
list($StartMicro, $StartSecond) = explode(" " , $this->StartTime);
list($StopMicro, $StopSecond) = explode(" ", $this->StopTime);
$start = doubleval($StartMicro) + $StartSecond;
$stop = doubleval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return substr($this->TimeSpent,0,8)." seconds ";//Return the obtained program running time difference
}
}
}
$timer = new Timer();
$timer->start();
/ /...The program running code
$timer->stop();
echo "The program running time is:".$timer->spent();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326150.htmlTechArticleCopy the code as follows: class Timer { private $StartTime = 0;//Program running start time private $StopTime = 0;//Program running end time private $TimeSpent = 0;//Program running cost...
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