Source for file Timer.class.php
Documentation is available at Timer.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
gumbo_load ("Interface_Timer");
/** @var array $_times list of record Times (or Laps) */
/** @var bool $_running */
/** @var bool $_stopped */
* @param bool $start starts the Timer
* Starts the Timer by recording the current time stamp
* @precondition !isRunning()
* @postcondition isStarted()
* @param bool $reset resets timer
public function start ($reset=
false) {
$e->setFunction (__METHOD__
);
// checks if the Timer is running
* Saves the Mark (or Lap)
* @precondition isRunning()
* Stops the Timer by recording the current time stamp
* @precondition isRunning()
* @postcondition isStopped()
public function stop () {
* @postcondition !isRunning()
* @postcondition isStopped()
public function reset () {
* Returns the actual microtime value of the given lap (0 => start time)
* @param int $lap (0 returns start time, if > laps() or negative, returns stop time)
public function stamp ($lap=
null) {
if ($lap <= -
1 ||
$lap >=
$this->laps ()) { $lap =
$this->laps () -
1; }
if (!isset
($this->_times [$lap])) {
$e->setFunction (__METHOD__
);
* Returns the time difference from the given lap to the previous lap
* If the parameter is null or 0, it will return the total time from
* start to stop recorded by the Timer. If parameter greater than total
* laps, it will return the difference from the Stop time to the previous
* @precondition laps() > 2
* @param int $lap lap number (if > laps(), returns last time)
* @param int $precision rounds the number to the given precision
public function time ($lap=
null, $precision=
null) {
if ($this->laps () <
2) {
if (!is_null ($precision) &&
$precision <
0) {
throw
new Gumbo_Exception ("Out Of Range 'precision >= 0' => {$precision}");
$e->setFunction (__METHOD__
);
$lap =
$this->laps () -
1;
if ($lap >=
$this->laps ()) {
$lap =
$this->laps () -
1;
$e->setFunction (__METHOD__
);
* Returns the average time between Laps
* @precondition laps() >= 2
* @param int $precision rounds the number to the given precision
public function average ($precision=
null) {
if ($this->laps () <
2) {
if (!is_null ($precision) &&
$precision <
0) {
throw
new Gumbo_Exception ("Out Of Range 'precision >= 0' => {$precision}");
$e->setFunction (__METHOD__
);
for ($x =
1;$x <
$this->laps ();$x++
) {
$total +=
$this->time ($x);
return round (($total /
$count), $precision);
$e->setFunction (__METHOD__
);
* Returns the number of Laps
public function laps () {
return $this->stamp (-
1);
* Returns if the Timer is running (or has been started)
* Returns if the Timer is stopped