Benchmark Class Reference
[General]

Functions to benchmark how long time some other code has taken to execute. More...

List of all members.

Public Member Functions

 __construct ()
 Constructor.
 start ()
 Start the timer.
 stop ()
 Stop the timer.
 getStartTime ()
 Get the start time.
 getStopTime ()
 Get the stop time.
 getElapsedTime ()
 Get the elapsed time between start and stop.

Private Attributes

 $_startAt
 The start time measured in the number of seconds since the Unix Epoch (1970).
 $_stopAt
 The stop time measured in the number of seconds since the Unix Epoch (1970).


Detailed Description

Functions to benchmark how long time some other code has taken to execute.

 $timer = new Benchmark();
 $timer->start();
 // do some stuff;
 $timer->stop();
 echo $timer->getElapsedTime();

Author:
Daniel Lindh <[email protected]>

Definition at line 16 of file Benchmark.class.php.


Constructor & Destructor Documentation

Benchmark::__construct (  ) 

Constructor.

Set the time zone to Europe/Stockholm.

Definition at line 23 of file Benchmark.class.php.

00024   {
00025     date_default_timezone_set('Europe/Stockholm');
00026     $this->_startAt = NULL;
00027     $this->_stopAt = NULL;
00028   }


Member Function Documentation

Benchmark::getElapsedTime (  ) 

Get the elapsed time between start and stop.

Returns:
- string -

Definition at line 76 of file Benchmark.class.php.

00077   {
00078     $totalSeconds = $this->_stopAt - $this->_startAt;
00079     $hours = floor($totalSeconds / 3600);
00080     $minutes = floor(($totalSeconds % 60) / 60);
00081     $seconds = ($totalSeconds % 3600);
00082     return str_pad($hours, 2, '0', STR_PAD_LEFT).':'.str_pad($minutes, 2, '0', STR_PAD_LEFT).':'.str_pad($seconds, 2, '0', STR_PAD_LEFT);
00083   }

Benchmark::getStartTime (  ) 

Get the start time.

Returns:
- date - The time the benchmark started

Definition at line 56 of file Benchmark.class.php.

00057   {
00058     return date('dMY H:i:s', $this->_startAt);
00059   }

Benchmark::getStopTime (  ) 

Get the stop time.

Returns:
- date - The time the benchmark stoped

Definition at line 66 of file Benchmark.class.php.

00067   {
00068     return date('dMY H:i:s', $this->_stopAt);
00069   }

Benchmark::start (  ) 

Start the timer.

Definition at line 33 of file Benchmark.class.php.

00034   {
00035     $this->_stopAt = NULL;
00036     $this->_startAt = time();
00037   }

Benchmark::stop (  ) 

Stop the timer.

Returns:
- int- The elapsed time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Definition at line 45 of file Benchmark.class.php.

00046   {
00047     $this->_stopAt = time();
00048     return $this->_stopAt - $this->_startAt;
00049   }


Member Data Documentation

Benchmark::$_startAt [private]

The start time measured in the number of seconds since the Unix Epoch (1970).

Definition at line 88 of file Benchmark.class.php.

Benchmark::$_stopAt [private]

The stop time measured in the number of seconds since the Unix Epoch (1970).

Definition at line 93 of file Benchmark.class.php.


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:28:24 2009 for fareofficelib by  doxygen 1.5.8