您的位置:首页 > 编程语言 > PHP开发

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 运行时间