Hoa central
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Hoa\Bench\Mark Class Reference

Public Member Functions

 __construct ($id)
 
 getId ()
 
 start ()
 
 stop ($silent=false)
 
 reset ()
 
 pause ($silent=false)
 
 diff ()
 
 compareTo (Mark $mark)
 
 isRunning ()
 
 isPause ()
 
 __toString ()
 

Public Attributes

const GLOBAL_NAME = '__global__'
 

Protected Member Functions

 setId ($id)
 

Protected Attributes

 $_id = null
 
 $start = 0.0
 
 $stop = 0.0
 
 $pause = 0.0
 
 $_running = false
 
 $_pause = false
 

Detailed Description

Class .

The class contains a collection of . Each mark can be start, pause, stop, reset, or compare to an other mark.

Definition at line 48 of file Mark.php.

Constructor & Destructor Documentation

Hoa\Bench\Mark::__construct (   $id)

Built a mark (and set the ID).

Parameters
string$idThe mark ID.
Returns
void

Definition at line 107 of file Mark.php.

108  {
109  $this->setId($id);
110 
111  return;
112  }
setId($id)
Definition: Mark.php:120

Here is the call graph for this function:

Member Function Documentation

Hoa\Bench\Mark::__toString ( )

Alias of the diff() method, but return a string, not a float.

Returns
string

Definition at line 325 of file Mark.php.

326  {
327  return (string) $this->diff();
328  }

Here is the call graph for this function:

Hoa\Bench\Mark::compareTo ( Mark  $mark)

Compare to mark. $a op $b : return -1 if $a < $b, 0 if $a == $b, and 1 if $a > $b. We compare the difference between $start and $stop, i.e. we call the diff() method.

Parameters
\Hoa\Bench\Mark$markThe mark to compare to.
Returns
int

Definition at line 286 of file Mark.php.

287  {
288  $a = $this->diff();
289  $b = $mark->diff();
290 
291  if ($a < $b) {
292  return -1;
293  } elseif ($a == $b) {
294  return 0;
295  } else {
296  return 1;
297  }
298  }

Here is the call graph for this function:

Hoa\Bench\Mark::diff ( )

Get the difference between $stop and $start. If the mark is still running (it contains the pause case), the current microtime will be used in stay of $stop.

Returns
float

Definition at line 268 of file Mark.php.

269  {
270  if (false === $this->isRunning() || true === $this->isPause()) {
271  return $this->stop - $this->start - $this->pause;
272  }
273 
274  return microtime(true) - $this->start - $this->pause;
275  }
stop($silent=false)
Definition: Mark.php:181

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Bench\Mark::getId ( )

Get the mark ID.

Returns
string

Definition at line 133 of file Mark.php.

134  {
135  return $this->_id;
136  }

Here is the caller graph for this function:

Hoa\Bench\Mark::isPause ( )

Check if the mark is in pause.

Returns
bool

Definition at line 315 of file Mark.php.

316  {
317  return $this->_pause;
318  }

Here is the caller graph for this function:

Hoa\Bench\Mark::isRunning ( )

Check if the mark is running.

Returns
bool

Definition at line 305 of file Mark.php.

306  {
307  return $this->_running;
308  }

Here is the caller graph for this function:

Hoa\Bench\Mark::pause (   $silent = false)

Pause the mark. A mark can be in pause if it is started. Else, an exception will be thrown (or not, according to the $silent argument).

Parameters
bool$silentIf set to true and the mark is not running, no exception will be throw. Idem if the mark is in pause.
Returns
Exceptions

Definition at line 229 of file Mark.php.

230  {
231  if (false === $this->isRunning()) {
232  if (false === $silent) {
233  throw new Exception(
234  'Cannot stop the %s mark, because it is not running.',
235  2,
236  $this->getId()
237  );
238  } else {
239  return $this;
240  }
241  }
242 
243  if (true === $this->isPause()) {
244  if (false === $silent) {
245  throw new Exception(
246  'The %s mark is still in pause. Cannot pause it again.',
247  3,
248  $this->getId()
249  );
250  } else {
251  return $this;
252  }
253  }
254 
255  $this->stop = microtime(true);
256  $this->_pause = true;
257 
258  return $this;
259  }
stop($silent=false)
Definition: Mark.php:181

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Bench\Mark::reset ( )

Reset the mark.

Returns

Definition at line 207 of file Mark.php.

208  {
209  $this->start = 0.0;
210  $this->stop = 0.0;
211  $this->pause = 0.0;
212  $this->_running = false;
213  $this->_pause = false;
214 
215  return $this;
216  }
stop($silent=false)
Definition: Mark.php:181
pause($silent=false)
Definition: Mark.php:229

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Bench\Mark::setId (   $id)
protected

Set the mark ID.

Parameters
string$idThe mark ID.
Returns
string

Definition at line 120 of file Mark.php.

121  {
122  $old = $this->_id;
123  $this->_id = $id;
124 
125  return $old;
126  }

Here is the caller graph for this function:

Hoa\Bench\Mark::start ( )

Start the mark. A mark can be started if it is in pause, stopped, or if it is the first start. Else, an exception will be thrown.

Returns
Exceptions

Definition at line 146 of file Mark.php.

147  {
148  if (true === $this->isRunning()) {
149  if (false === $this->isPause()) {
150  throw new Exception(
151  'Cannot start the %s mark, because it is running.',
152  0,
153  $this->getId()
154  );
155  }
156  }
157 
158  if (true === $this->isPause()) {
159  $this->pause += microtime(true) - $this->stop;
160  } else {
161  $this->reset();
162  $this->start = microtime(true);
163  }
164 
165  $this->_running = true;
166  $this->_pause = false;
167 
168  return $this;
169  }
pause($silent=false)
Definition: Mark.php:229

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Bench\Mark::stop (   $silent = false)

Stop the mark. A mark can be stopped if it is in pause, or started. Else, an exception will be thrown (or not, according to the $silent argument).

Parameters
bool$silentIf set to true and if the mark is not running, no exception will be thrown.
Returns
Exceptions

Definition at line 181 of file Mark.php.

182  {
183  if (false === $this->isRunning()) {
184  if (false === $silent) {
185  throw new Exception(
186  'Cannot stop the %s mark, because it is not running.',
187  1,
188  $this->getId()
189  );
190  } else {
191  return $this;
192  }
193  }
194 
195  $this->stop = microtime(true);
196  $this->_running = false;
197  $this->_pause = false;
198 
199  return $this;
200  }
stop($silent=false)
Definition: Mark.php:181

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Bench\Mark::$_id = null
protected

Definition at line 62 of file Mark.php.

Hoa\Bench\Mark::$_pause = false
protected

Definition at line 97 of file Mark.php.

Hoa\Bench\Mark::$_running = false
protected

Definition at line 90 of file Mark.php.

Hoa\Bench\Mark::$pause = 0.0
protected

Definition at line 83 of file Mark.php.

Hoa\Bench\Mark::$start = 0.0
protected

Definition at line 69 of file Mark.php.

Hoa\Bench\Mark::$stop = 0.0
protected

Definition at line 76 of file Mark.php.

const Hoa\Bench\Mark::GLOBAL_NAME = '__global__'

Name of the global mark.

string

Definition at line 55 of file Mark.php.


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