<?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) . '毫秒';
}
}
?>