Skip to content

Commit 29bf39c

Browse files
committed
Improve performance by avoiding platform checks during runtime
1 parent eae7096 commit 29bf39c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Timer/Timers.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ final class Timers
1818
private $timers = array();
1919
private $schedule = array();
2020
private $sorted = true;
21+
private $useHighResolution;
2122

22-
public function updateTime()
23+
public function __construct()
2324
{
2425
// prefer high-resolution timer, available as of PHP 7.3+
25-
if (\function_exists('hrtime')) {
26-
return $this->time = \hrtime(true) * 1e-9;
27-
}
26+
$this->useHighResolution = \function_exists('hrtime');
27+
}
2828

29-
return $this->time = \microtime(true) + 1000;
29+
public function updateTime()
30+
{
31+
return $this->time = $this->useHighResolution ? \hrtime(true) * 1e-9 : \microtime(true);
3032
}
3133

3234
public function getTime()

0 commit comments

Comments
 (0)