计算php代码执行时间长短的类
2018-01-08 11:19
746 查看
<?php
/**
* PHP脚本执行时间计算
*/
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($echo=false,$title='')
{
$spent = sprintf('%.4f',round(($this->StopTime - $this->StartTime) * 1000, 1)/1000);
if($echo){
echo $title."执行时间:{$spent}秒<br/>";
}else{
return $spent;
}
}
function clear()
{
$this->StartTime = 0;
$this->StopTime = 0;
}
}
#测试脚本代码
$runtime= new runtime;
$runtime->start();
$a = 0;
for($i=0; $i<100000; $i++)
{
$a *= $i;
}
$runtime->stop();
$spent_time = $runtime->spent($echo=true, '测试脚本');
$runtime->clear();
?>
/**
* PHP脚本执行时间计算
*/
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($echo=false,$title='')
{
$spent = sprintf('%.4f',round(($this->StopTime - $this->StartTime) * 1000, 1)/1000);
if($echo){
echo $title."执行时间:{$spent}秒<br/>";
}else{
return $spent;
}
}
function clear()
{
$this->StartTime = 0;
$this->StopTime = 0;
}
}
#测试脚本代码
$runtime= new runtime;
$runtime->start();
$a = 0;
for($i=0; $i<100000; $i++)
{
$a *= $i;
}
$runtime->stop();
$spent_time = $runtime->spent($echo=true, '测试脚本');
$runtime->clear();
?>
相关文章推荐
- 计算php代码执行时间长短的类(精确到毫秒)
- php使用microtime(true)计算php程序代码执行消耗时间
- php 页面执行时间计算代码
- php使用microtime(true)计算php程序代码执行消耗时间
- 解读PHP计算页面执行时间的具体代码实现
- 解析PHP计算页面执行时间的实现代码
- php 页面执行时间计算代码
- php使用microtime(true)计算php程序代码执行消耗时间
- php 页面执行时间计算代码
- php计算代码执行时间
- php 计算代码执行时间
- php页面执行计算时间代码
- 解析PHP计算页面执行时间的实现代码
- php计算某段代码执行时间
- php 计算代码执行时间
- php 计算代码执行时间
- php 计算页面执行时间来优化代码
- c++计算代码执行时间的方法,毫秒级
- 计算php页面执行时间