php实现用于计算执行时间的类实例
作者:不吃皮蛋 时间:2024-06-07 15:28:42
本文实例讲述了php实现用于计算执行时间的类。分享给大家供大家参考。具体如下:
有了这个php类,计算函数或者一段代码的执行时间就简单了
<?php
class c_Timer {
var $t_start = 0;
var $t_stop = 0;
var $t_elapsed = 0;
function start() {
$this->t_start = microtime();
}
function stop() {
$this->t_stop = microtime();
}
function elapsed() {
if ($this->t_elapsed) {
return $this->t_elapsed;
} else {
$start_u = substr($this->t_start,0,10);
$start_s = substr($this->t_start,11,10);
$stop_u = substr($this->t_stop,0,10);
$stop_s = substr($this->t_stop,11,10);
$start_total = doubleval($start_u) + $start_s;
$stop_total = doubleval($stop_u) + $stop_s;
$this->t_elapsed = $stop_total - $start_total;
return $this->t_elapsed;
}
}
};
?>
用法示例如下:
<?php
$timer = new c_Timer;
$timer->start();
echo "<hr>";
$timer->stop();
echo $timer->elapsed();
?>
希望本文所述对大家的php程序设计有所帮助。
标签:php,执行,时间
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现读取大文件并逐行写入另外一个文件
2021-02-03 21:10:45
css清除浮动“clear:both;”的应用
2008-03-17 12:54:00
mysql实现设置定时任务的方法分析
2024-01-18 03:37:18
MySql InnoDB存储引擎之Buffer Pool运行原理讲解
2024-01-27 01:46:50
![](https://img.aspxhome.com/file/2023/6/129896_0s.png)
String与string的区别(注意大小写)
2023-06-28 22:04:13
python 浮点数四舍五入需要注意的地方
2021-11-04 04:37:56
![](https://img.aspxhome.com/file/2023/1/115621_0s.jpg)
Python函数参数基础介绍及示例
2021-02-03 03:11:04
django时区问题的解决
2022-06-09 10:56:45
JavaScript风格要素
2007-10-25 16:57:00
Python关于拓扑排序知识点讲解
2022-09-12 15:04:22
![](https://img.aspxhome.com/file/2023/8/127248_0s.png)
go语言获取系统盘符的方法
2024-05-22 10:19:47
python 的 scapy库,实现网卡收发包的例子
2021-08-08 17:25:05
SQL Server 数据库索引其索引的小技巧
2012-07-11 15:55:02
WEB页面工具语言XML应用分类之运用
2008-05-29 10:58:00
c++与python实现二分查找的原理及实现
2021-11-23 21:09:06
![](https://img.aspxhome.com/file/2023/3/128173_0s.gif)
Python通过2种方法输出带颜色字体
2023-02-08 20:53:22
![](https://img.aspxhome.com/file/2023/7/71507_0s.png)
mysql 5.7.13 安装配置方法图文教程(win10)
2024-01-14 06:51:48
![](https://img.aspxhome.com/file/2023/6/105496_0s.jpg)
python基础教程之基本内置数据类型介绍
2023-02-12 07:19:31
ajax完美实现两个网页 分页功能的实例代码
2023-11-14 12:57:27
Javascript 字符串模板的简单实现
2024-05-02 17:30:37