日期:2015-04-17 分类:网络技术 浏览:8398 来源:邦明科技
PHP计算程序执行时间最简单的代码如下:
<?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>";
?>下一篇: 谷歌多语言网站翻译代码,国内加载快的方法