测试PHP代码和页面执行速度的类
2015-12-08 21:46
1906 查看
<?php
class timer {
var $StartTime = 0;
var $StopTime = 0;
var $TimeSpent = 0;
function start(){
$this->StartTime = microtime();
}
function stop(){
$this->StopTime = microtime();
}
function spent() {
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
$StartMicro = substr($this->StartTime,0,10);
$StartSecond = substr($this->StartTime,11,10);
$StopMicro = substr($this->StopTime,0,10);
$StopSecond = substr($this->StopTime,11,10);
$start = floatval($StartMicro) + $StartSecond;
$stop = floatval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return round($this->TimeSpent,8).'秒';
}
} // end function spent();
} //end class timer;
//$timer = new timer;//实例化测试类
//$timer->start();//放在代码开始执行的测试点
//$timer->stop(); //放在代码执行结束的测试点
//print_r('</br>运行时间为: '.$timer->spent()) ;
//unset($timer);
class timer {
var $StartTime = 0;
var $StopTime = 0;
var $TimeSpent = 0;
function start(){
$this->StartTime = microtime();
}
function stop(){
$this->StopTime = microtime();
}
function spent() {
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
$StartMicro = substr($this->StartTime,0,10);
$StartSecond = substr($this->StartTime,11,10);
$StopMicro = substr($this->StopTime,0,10);
$StopSecond = substr($this->StopTime,11,10);
$start = floatval($StartMicro) + $StartSecond;
$stop = floatval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return round($this->TimeSpent,8).'秒';
}
} // end function spent();
} //end class timer;
//$timer = new timer;//实例化测试类
//$timer->start();//放在代码开始执行的测试点
//$timer->stop(); //放在代码执行结束的测试点
//print_r('</br>运行时间为: '.$timer->spent()) ;
//unset($timer);
相关文章推荐
- PHP正则提取或替换img标记属性内容
- PHP页面编码问题处理
- JetBrains系列新版本注册激活包括IDEA15,PHPSTORM10,WEBSTORM11
- PHP通用检测函数集合
- PHP实现在文章中加内链的实例(只替换一次)
- PHP页面跳转报错
- 华为交换机STP的配置
- PHP生成缩略图的方法和实例
- php curl_exec optimize
- 基于PHP的cURL使用入门
- PHP数组操作汇总
- PHP常见出错及解决方案(5)
- 【 一次性密码】TOTP
- EditPlus注册码在线生成
- php数据库访问
- php加密技术
- php 给图片添加水印
- php源码分析之base64_encode函数
- 七牛---关于PHP SDK的各种Demo
- PHP.ini文件 服务器将用户可操作的文件限制在某目录下