Skip to content

Commit dd09a6b

Browse files
IonBazannicolas-grekas
authored andcommitted
Add hrtime() function
1 parent 9841f6f commit dd09a6b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Php73.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Symfony\Polyfill\Php73;
4+
5+
/**
6+
* @author Gabriel Caruso <[email protected]>
7+
* @author Ion Bazan <[email protected]>
8+
*
9+
* @internal
10+
*/
11+
final class Php73
12+
{
13+
public static $startAt = 1533462603;
14+
15+
/**
16+
* @param bool $asNum
17+
*
18+
* @return array|float|int
19+
*/
20+
public static function hrtime($asNum = false)
21+
{
22+
$ns = \microtime(false);
23+
$s = \strstr($ns, ' ') - self::$startAt;
24+
$ns = 1E9 * (float) $ns;
25+
26+
if ($asNum) {
27+
$ns += $s * 1E9;
28+
29+
return \PHP_INT_SIZE === 4 ? $ns : (int) $ns;
30+
}
31+
32+
return array($s, (int) $ns);
33+
}
34+
}

bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
use Symfony\Polyfill\Php73 as p;
13+
1214
if (PHP_VERSION_ID < 70300) {
1315
if (!function_exists('is_countable')) {
1416
function is_countable($var) { return is_array($var) || $var instanceof Countable || $var instanceof ResourceBundle || $var instanceof SimpleXmlElement; }
1517
}
18+
19+
if (!function_exists('hrtime')) {
20+
p\Php73::$startAt = (int) microtime(true);
21+
function hrtime($asNum = false) { return p\Php73::hrtime($asNum); }
22+
}
1623
}

0 commit comments

Comments
 (0)