1 | <?php |
||
19 | final class Stopwatch |
||
20 | { |
||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | private $time; |
||
25 | |||
26 | /** |
||
27 | * @var float |
||
28 | */ |
||
29 | private $elapsed; |
||
30 | |||
31 | /** |
||
32 | * @var bool |
||
33 | */ |
||
34 | private $isRunning; |
||
35 | |||
36 | 5 | private function __construct() |
|
40 | |||
41 | /** |
||
42 | * @return Stopwatch |
||
43 | */ |
||
44 | 5 | public static function createNew(): self |
|
48 | |||
49 | /** |
||
50 | * Starts or resumes measurement. |
||
51 | * |
||
52 | 7 | * @return void |
|
53 | */ |
||
54 | 7 | public function start(): void |
|
64 | |||
65 | /** |
||
66 | 2 | * Stops measurement. |
|
67 | * |
||
68 | 2 | * @return void |
|
69 | 2 | */ |
|
70 | 2 | public function stop(): void |
|
75 | 1 | ||
76 | /** |
||
77 | 1 | * Stops measurement and starts from the beginning. |
|
78 | 1 | * |
|
79 | 1 | * @return void |
|
80 | */ |
||
81 | public function restart(): void |
||
86 | 1 | ||
87 | 1 | /** |
|
88 | * Stops measurement and resets elapsed time. |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | 10 | public function reset(): void |
|
96 | 10 | ||
97 | /** |
||
98 | * @return float |
||
99 | */ |
||
100 | public function getElapsed(): float |
||
106 | |||
107 | /** |
||
108 | * @return int |
||
109 | */ |
||
110 | 1 | public function getElapsedSeconds(): int |
|
114 | |||
115 | /** |
||
116 | * @return int |
||
117 | */ |
||
118 | 1 | public function getElapsedMilliseconds(): int |
|
122 | |||
123 | /** |
||
124 | * @return int |
||
125 | */ |
||
126 | public function getElapsedMicroseconds(): int |
||
130 | |||
131 | /** |
||
132 | * Returns true if stopwatch is running, otherwise false. |
||
133 | * |
||
134 | * @return bool |
||
135 | 7 | */ |
|
136 | public function isRunning(): bool |
||
140 | 7 | ||
141 | /** |
||
142 | * Initializes stopwatch internals. |
||
143 | * |
||
144 | * @return void |
||
145 | 10 | */ |
|
146 | private function init(): void |
||
152 | 8 | ||
153 | /** |
||
154 | * Stores elapsed time. |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | private function storeElapsed(): void |
||
166 | } |
||
167 |