PHP 计算程序运行的时间
<?php
class SpendTime {
static function Start($sTransName) {
SpendTime::$arrStartTimes [$sTransName] = microtime ( true );
}
static function End($sTransName) {
SpendTime::$arrSpendTimes [$sTransName] = microtime ( true ) – SpendTime::$arrStartTimes [$sTransName];
}
static function PrintTime() {
echo “<pre>”;
print_r ( SpendTime::$arrSpendTimes );
echo “</pre>”;
}
static $arrStartTimes = array ();
static $arrEndTimes = array ();
static $arrSpendTimes = array ();
}
?>
使用方法,如计算出echo 的执行时间:
SpendTime::Start(‘echo’);
SpendTime::End(‘echo’);
SpendTime::PrintTime();