一个计算页面执行时间的简单类
程序员文章站
2022-03-04 13:07:15
...
以后可能会扩充些实用的功能
用法:
用法:
<?php
include 'stopwatch.php';
$timer = new Stopwatch();
$timer->start();
//这里是要统计执行时间的代码
$timer->stop();
echo $timer->getTime();
?>
<?php
/*
* @author badboy
* @2009-06-02
* class Stopwatch
* 此类可用于计算程序运行时间
* 以此观察效率
*/
class Stopwatch
{
var $previousTime;
var $timeCost; //所用时间
//constructor
function Stopwatch()
{
$this->timeCost=0;
}
function getCurrentTime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
//start
function start()
{
$this->timeCost = 0;
$this->previousTime=$this->getCurrentTime();
}
//stop
function stop()
{
$this->timeCost = $this->getCurrentTime() - $this->previousTime;
}
//get time
function getTime()
{
return $this->timeCost;
}
}
?>
上一篇: Python文件名和文件路径常用操作
下一篇: uchome中的发送邮件