<?php
/*
*計算程序運行時間的類
* 單位:毫秒
* 調用方案:
* 程序開頭:$time = new time(); $time->start();
* 程序結尾:$time->stop();
* echo "程序運行時間爲:".$time->spent();
* */
class Time
{
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) . '毫秒';
}
}
?>