3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * ## Hex to string. For GPON SN * * @param $hex * @return string * * * @example * hex2str('5A544547')."C193E72F"; <p>return ZTEGC193E72F</p> */ function hex2str($hex) { $string = ''; for ($i = 0; $i < strlen($hex) - 1; $i += 2) { $string .= chr(hexdec($hex[$i] . $hex[$i + 1])); } return $string; } // echo hex2str('5A544547')."C193E72F"; // ZTEGC193E72F /** * ## обработка полученного от SNMP интерфейса * форматы snmp интерфейса: * - 269422592.5 * - 2432632064 * - 808398336 * @param $snmp_interface * @return array|void */ function decode_snmp_interface($snmp_interface) { // 269422592.5 if (preg_match('/(?P<pon>\d+)\.(?P<onu>\d+)/', $snmp_interface, $dotInterface)) { /** ## $dotInterface ``` Array ( [0] => 269422592.5 [pon] => 269422592 [1] => 269422592 [onu] => 5 [2] => 5 ) ``` */ $b = decbin(substr($snmp_interface, 0, 9)); $type = bindec(substr($b, 0, 4)); $shelf = bindec(substr($b, 4, 4)) + 1; $slot = bindec(substr($b, 8, 5)); $port = bindec(substr($b, 13, 8)); $reserved = bindec(substr($b, 21, 8)); $onu = $dotInterface['onu']; } // первая цифра числа == 8 elseif (strval($snmp_interface)[0] == 8) { $b = "00" . decbin($snmp_interface); $type = bindec(substr($b, 0, 4)); $shelf = bindec(substr($b, 4, 4)) + 1; $slot = bindec(substr($b, 8, 5)); $port = bindec(substr($b, 13, 3)) + 1; $onu = bindec(substr($b, 16, 8)); $reserved = bindec(substr($b, 24, 8)); } elseif (strval($snmp_interface)[0] == 2) { $b = decbin($snmp_interface); $type = bindec(substr($b, 0, 4)); $shelf = bindec(substr($b, 4, 4)) + 1; $slot = bindec(substr($b, 8, 4)); $port = bindec(substr($b, 12, 4)) + 1; $onu = bindec(substr($b, 16, 8)); $reserved = bindec(substr($b, 24, 8)); } return [ 'shelf' => $shelf, 'slot' => $slot, 'port' => $port, 'onu' => $onu, 'string' => "$shelf/$slot/$port:$onu", 'snmp_interface' => $snmp_interface, 'db_interface' => 'todo' ]; } /** * # testing */ $a = [ '269422592.5' => '1/15/16:5', '269222144.1' => '1/12/1:1', '268963840.5' => '1/8/16:5', '808398336' => '1/5/8:46', '806356736' => '1/2/1:7', '2428502272' => '1/12/1:1', '2421364992' => '1/5/4:25', '2432632064' => '1/15/16:5' ]; foreach ($a as $snmp_interface => $string){ $arr = decode_snmp_interface($snmp_interface); if($arr['string'] == $string) echo "$snmp_interface \t tested ok"; else echo "$snmp_interface \t testing failed. must be $string, but is [{$arr['string']}]"; echo "\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.00.0130.00920.30
8.4.150.0020.00014.05
8.4.140.0100.01017.73
8.4.130.0120.00919.70
8.4.120.0130.00820.40
8.4.110.0100.00622.32
8.4.100.0080.00120.52
8.4.90.0110.00618.50
8.4.80.0130.00818.04
8.4.70.0120.00718.32
8.4.60.0070.01318.82
8.4.50.0130.00720.63
8.4.40.0150.00617.87
8.4.30.0100.01019.02
8.4.20.0140.00318.20
8.4.10.0090.00019.42
8.3.280.0100.01118.60
8.3.270.0090.01016.79
8.3.260.0090.00416.58
8.3.250.0130.00819.30
8.3.240.0030.00516.89
8.3.230.0090.01016.85
8.3.220.0050.00317.35
8.3.210.0110.00816.97
8.3.200.0050.00516.98
8.3.190.0040.00417.32
8.3.180.0080.00716.96
8.3.170.0150.00419.13
8.3.160.0060.01318.37
8.3.150.0180.00317.25
8.3.140.0000.00818.89
8.3.130.0060.00318.42
8.3.120.0050.00319.05
8.3.110.0060.00320.94
8.3.100.0100.01016.79
8.3.90.0080.01126.77
8.3.80.0050.00518.30
8.3.70.0110.01116.88
8.3.60.0110.01116.88
8.3.50.0100.00616.77
8.3.40.0150.00020.18
8.3.30.0100.00320.51
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0150.00628.09
8.2.290.0060.00420.48
8.2.280.0080.01120.21
8.2.270.0110.00817.10
8.2.260.0000.01018.67
8.2.250.0050.00316.96
8.2.240.0030.00619.24
8.2.230.0060.00322.58
8.2.220.0120.00324.06
8.2.210.0100.01426.77
8.2.200.0060.00318.41
8.2.190.0210.00018.54
8.2.180.0100.00625.92
8.2.170.0150.00019.16
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0160.00428.09
8.2.120.0060.00928.09
8.2.110.0130.00328.09
8.2.100.0160.00628.09
8.2.90.0180.00428.09
8.2.80.0060.01228.09
8.2.70.0160.00328.09
8.2.60.0170.00328.09
8.2.50.0150.00028.09
8.2.40.0120.00328.09
8.2.30.0090.00628.09
8.2.20.0070.01028.09
8.2.10.0080.00828.09
8.2.00.0120.00328.09
8.1.330.0140.00723.64
8.1.320.0100.00916.23
8.1.310.0130.00618.58
8.1.300.0130.00319.88
8.1.290.0090.00030.84
8.1.280.0120.00325.92
8.1.270.0040.00423.98
8.1.260.0050.00328.09
8.1.250.0090.00628.09
8.1.240.0110.00428.09
8.1.230.0120.00328.09
8.1.220.0030.00628.09
8.1.210.0060.00328.09
8.1.200.0040.00428.09
8.1.190.0040.00428.09
8.1.180.0040.00428.09
8.1.170.0080.00028.09
8.1.160.0060.00328.09
8.1.150.0060.00328.09
8.1.140.0030.00628.09
8.1.130.0060.00328.09
8.1.120.0060.00328.09
8.1.110.0030.00628.09
8.1.100.0040.00428.09
8.1.90.0000.00828.09
8.1.80.0060.00328.09
8.1.70.0060.00328.09
8.1.60.0060.00328.09
8.1.50.0050.00328.09
8.1.40.0030.00628.09
8.1.30.0080.00028.09
8.1.20.0050.00328.09
8.1.10.0030.00528.09
8.1.00.0060.00328.09

preferences:
81.75 ms | 403 KiB | 5 Q