timer类,计算脚本的运行时间
2013-10-30 11:26
441 查看
源码
运行演示代码:
class timer { var $start; var $pause_time; /* start the timer */ function timer($start = 0) { if($start) { $this->start(); } } /* start the timer */ function start() { $this->start = $this->get_time(); $this->pause_time = 0; } /* pause the timer */ function pause() { $this->pause_time = $this->get_time(); } /* unpause the timer */ function unpause() { $this->start += ($this->get_time() - $this->pause_time); $this->pause_time = 0; } /* get the current timer value */ function get($decimals = 8) { return round(($this->get_time() - $this->start),$decimals); } /* format the time in seconds */ function get_time() { list($usec,$sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } }
运行演示代码:
<?php include "timer.class.php"; $timer = new timer(1); /**php代码 开始**/ /**php代码 结束**/ //运行时间 $query_time = $timer->get(); echo $query_time; /**php代码 开始**/ /**php代码 结束**/ //运行时间 $processing_time = $timer->get(); echo $processing_time;
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- PHP 5.3.0 安装分析心得
- apache 环境下 php 的配置注意事项
- ASP.NET、ASP、PHP、JSP之间有什么区别?
- PHP VBS JS 函数 对照表
- php xml 入门学习资料
- PHP简单系统数据添加以及数据删除模块源文件下载
- php-accelerator网站加速PHP缓冲的方法