The page execution time calculation is only a rough process. We put the initialization function of the program calculation program at the top of the page, and then put the calculation function at the bottom of the page. Then when the page execution is completed, the relevant values can be calculated. Let’s look at the example
specific code
The code is as follows
代码如下 |
复制代码 |
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function start()
{
$this->StartTime = $this->get_microtime();
}
function stop()
{
$this->StopTime = $this->get_microtime();
}
function spent()
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}
}
//例子
$runtime= new runtime;
$runtime->start();
//你的代码开始
$a = 0;
for($i=0; $i<1000000; $i++)
{
$a += $i;
}
//你的代码结束
$runtime->stop();
echo "页面执行时间: ".$runtime->spent()." 毫秒";
?>
|
|
Copy code
|
class runtime |
{
var $StartTime = 0;
var $StopTime = 0;
Function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
Function start()
{
$this->StartTime = $this->get_microtime();
}
Function stop()
{
$this->StopTime = $this->get_microtime();
}
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}
}
//Example
$runtime= new runtime;
$runtime->start();
//Start of your code
$a = 0;
for($i=0; $i<1000000; $i++)<🎜>
{<🎜>
$a += $i;<🎜>
}<🎜>
<🎜>
//End of your code<🎜>
<🎜>
$runtime->stop();
echo "Page execution time: ".$runtime->spent()." milliseconds";
?>
The calling method has been introduced above, so I won’t go into details. We just need to note that $runtime->start(); and $runtime->spent() must be one after the other, otherwise it will be invalid and cannot be used. Put it in the cache page and html page.
http://www.bkjia.com/PHPjc/631559.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631559.htmlTechArticleThe page execution time calculation is only a rough process. We put the initialization function of the program calculation program at the top of the page. , then put the calculation function at the bottom of the page, and then when the page...
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