PHP程序执行/运行时间计算简单的代码 时间:2015-06-17 点击:次
<?php
//程序运行时间类
class timer {
private $StartTime = 0;//程序运行开始时间
private $StopTime = 0;//程序运行结束时间
private $TimeSpent = 0;//程序运行花费时间
function start(){//程序运行开始
$this->StartTime = microtime(true);
}
function stop(){//程序运行结束
$this->StopTime = microtime(true);
}
function spent(){//程序运行花费的时间
$this->TimeSpent=$this->StopTime-$this->StartTime;
return number_format($this->TimeSpent*1000, 4).'毫秒';//返回获取到的程序运行时间差
}
}
$timer = new timer();
$timer->start();
//所要执行的程序
$timer->stop();
//echo "程序运行时间为:".$timer->spent();
echo "<script language=javascript>alert('程序运行时间为:".$timer->spent()."');</script>";
?>
通过,执行上面的代码很容易计算出PHP语言的执行时间。是不是很简单,赶快试试吧~~~ 以上信息是有欣零点网络收集整理,如果您有做网站这方面的业务,欢迎您的来电咨询,我们竭诚为您提供优质服务。