mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
First public release of MyAAC
This commit is contained in:
56
system/libs/timer.php
Normal file
56
system/libs/timer.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Timer class
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2017 MyAAC
|
||||
* @version 0.0.1
|
||||
* @link http://my-aac.org
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
class Timer
|
||||
{
|
||||
private $start = 0;
|
||||
private $stop = 0;
|
||||
private $elapsed = 0;
|
||||
|
||||
function __construct($start = true) {
|
||||
if($start) $this->start();
|
||||
}
|
||||
|
||||
function start() {
|
||||
$this->start = $this->_gettime();
|
||||
}
|
||||
|
||||
function stop()
|
||||
{
|
||||
$this->stop = $this->_gettime();
|
||||
$this->elapsed = $this->_compute();
|
||||
}
|
||||
|
||||
function elapsed()
|
||||
{
|
||||
if(!$this->elapsed)
|
||||
$this->stop();
|
||||
|
||||
return $this->elapsed;
|
||||
}
|
||||
|
||||
function reset()
|
||||
{
|
||||
$this->start = 0;
|
||||
$this->stop = 0;
|
||||
$this->elapsed = 0;
|
||||
}
|
||||
|
||||
private function _gettime() {
|
||||
return microtime(true);
|
||||
}
|
||||
|
||||
private function _compute() {
|
||||
return $this->stop - $this->start;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user