|
Revision 9079, 1.6 kB
(checked in by Carl.Vondrick, 5 years ago)
|
1.1: fixed @param phpdoc to fit specs in debug (refs #2991)
|
- Property svn:mime-type set to
text/x-php
- Property svn:eol-style set to
native
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfTimer |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$startTime = null, |
|---|
| 23 |
$totalTime = null, |
|---|
| 24 |
$name = '', |
|---|
| 25 |
$calls = 0; |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
* Creates a new sfTimer instance. |
|---|
| 29 |
* |
|---|
| 30 |
* @param string $name The name of the timer |
|---|
| 31 |
*/ |
|---|
| 32 |
public function __construct($name = '') |
|---|
| 33 |
{ |
|---|
| 34 |
$this->name = $name; |
|---|
| 35 |
$this->startTimer(); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* Starts the timer. |
|---|
| 40 |
*/ |
|---|
| 41 |
public function startTimer() |
|---|
| 42 |
{ |
|---|
| 43 |
$this->startTime = microtime(true); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Stops the timer and add the amount of time since the start to the total time. |
|---|
| 48 |
* |
|---|
| 49 |
* @return float Time spend for the last call |
|---|
| 50 |
*/ |
|---|
| 51 |
public function addTime() |
|---|
| 52 |
{ |
|---|
| 53 |
$spend = microtime(true) - $this->startTime; |
|---|
| 54 |
$this->totalTime += $spend; |
|---|
| 55 |
++$this->calls; |
|---|
| 56 |
|
|---|
| 57 |
return $spend; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* Gets the number of calls this timer has been called to time code. |
|---|
| 62 |
* |
|---|
| 63 |
* @return integer Number of calls |
|---|
| 64 |
*/ |
|---|
| 65 |
public function getCalls() |
|---|
| 66 |
{ |
|---|
| 67 |
return $this->calls; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
* Gets the total time elapsed for all calls of this timer. |
|---|
| 72 |
* |
|---|
| 73 |
* @return float Time in seconds |
|---|
| 74 |
*/ |
|---|
| 75 |
public function getElapsedTime() |
|---|
| 76 |
{ |
|---|
| 77 |
if (null === $this->totalTime) |
|---|
| 78 |
{ |
|---|
| 79 |
$this->addTime(); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
return $this->totalTime; |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|