65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace BRSystems\Core\Library\cTimer;
|
|
|
|
/**
|
|
* This class allows a user to to determine execution
|
|
* time of code blocks.
|
|
*
|
|
* @author John Ciacia <Sidewinder@extreme-hq.com>
|
|
* @version 1.0
|
|
* @copyright Copyright © 2007, John Ciacia
|
|
* @license [url=http://opensource.org/licenses/gpl-license.php]Open Source Initiative OSI - The GPL:Licensing | Open Source Initiative[/url] GNU Public License
|
|
*/
|
|
class cTimer
|
|
{
|
|
var $starttime = 0;
|
|
var $endtime = 0;
|
|
var $elapsed = 0;
|
|
var $timername = "Not Named";
|
|
|
|
public function __construct() {
|
|
$this->start();
|
|
}
|
|
|
|
public function start() {
|
|
$this->starttime = $this->_time();
|
|
}
|
|
|
|
public function stop() {
|
|
$this->endtime = $this->_time();
|
|
$this->_compute();
|
|
return $this->elapsed;
|
|
}
|
|
|
|
public function clear() {
|
|
$this->starttime = 0;
|
|
$this->endtime = 0;
|
|
$this->elapsed = 0;
|
|
$this->timername = "Not Named";
|
|
}
|
|
|
|
public function elapsed() {
|
|
return $this->elapsed;
|
|
}
|
|
|
|
public function settimername($name) {
|
|
$this->timername = $name;
|
|
}
|
|
|
|
public function gettimername() {
|
|
return $this->timername;
|
|
}
|
|
|
|
private function _time() {
|
|
$mtime = microtime();
|
|
$mtime = explode(' ', $mtime);
|
|
$mtime = $mtime[1] + $mtime[0];
|
|
return $mtime;
|
|
}
|
|
|
|
private function _compute() {
|
|
$this->elapsed = (($this->endtime) - ($this->starttime));
|
|
}
|
|
}
|