php中计算程序运行时间的类代码
网络编程 2021-07-05 09:49www.168986.cn编程入门
一个用来技术你程序运行时间的php类,有需要的朋友可参考一下
代码如下:
class Timer {
private $StartTime = 0;//程序运行开始时间
private $STime = 0;//程序运行结束时间
private $TimeSpent = 0;//程序运行花费时间
function start(){//程序运行开始
$this->StartTime = microtime();
}
function s(){//程序运行结束
$this->STime = microtime();
}
function spent(){//程序运行花费的时间
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
list($StartMicro, $StartSecond) = explode(" ", $this->StartTime);
list($SMicro, $SSecond) = explode(" ", $this->STime);
$start = doubleval($StartMicro) + $StartSecond;
$s = doubleval($SMicro) + $SSecond;
$this->TimeSpent = $s - $start;
return substr($this->TimeSpent,0,8)."秒";//返回获取到的程序运行时间差
}
}
}
$timer = new Timer();
$timer->start();
//...程序运行的代码
$timer->s();
echo "程序运行时间为:".$timer->spent();
上一篇:PHP关联链接常用代码
下一篇:php教程 插件机制在PHP中实现方案
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程