3v4l.org

run code in 300+ PHP versions simultaneously
<?php function romanToDecimal($num) { $dec = 0; $i = 0; $romans = ['M', 'D', 'C', 'L', 'X', 'V', 'I']; $decs = [1000, 500, 100, 50, 10, 5, 1]; $rptr = 0; $num .= ' '; while ($i < strlen($num) - 1) { if ($num[$i] === $romans[$rptr]) { if (($rptr > 0) && ($num[$i + 1] === $romans[$rptr - 1])) { $dec -= $decs[$rptr]; $rptr -= 1; } else if (($rptr > 1) && ($num[$i + 1] === $romans[$rptr - 2])) { $dec -= $decs[$rptr]; $rptr -= 2; } else { $dec += $decs[$rptr]; } $i++; } else { $rptr++; if($rptr > count($decs)) return -1; } } return $dec; } function decimal2roman($num) { $romans = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; $decs = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; $len = count($decs); $rom = ''; while ($num) { $i = 0; while ($decs[$i++] > $num && $i < $len); $rom .= $romans[$i]; $num -= $decs[$i]; } return $rom; } echo romanToDecimal('MCXII') . "\n"; echo romanToDecimal('LIII') . "\n"; echo romanToDecimal('XCIX') . "\n"; echo romanToDecimal('XLVII') . "\n"; echo romanToDecimal('I') . "\n"; echo romanToDecimal('IV') . "\n"; echo romanToDecimal('DCCCXCIX') . "\n"; echo romanToDecimal('MMMCMXCIX') . "\n"; echo decimal2roman(128) . "\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.3.60.0160.00316.63
8.3.50.0250.01022.04
8.3.40.0380.00518.66
8.3.30.0120.00419.04
8.3.20.0170.00820.29
8.3.10.0030.00623.71
8.3.00.0090.00320.77
8.2.180.0140.00716.75
8.2.170.0180.00718.92
8.2.160.0250.00722.96
8.2.150.0000.00924.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0050.00522.08
8.2.110.0000.01022.24
8.2.100.0060.01117.84
8.2.90.0140.00319.22
8.2.80.0050.01017.97
8.2.70.0120.00317.63
8.2.60.0030.00818.04
8.2.50.0050.00518.07
8.2.40.0060.00319.34
8.2.30.0000.00918.09
8.2.20.0030.00617.75
8.2.10.0060.00319.71
8.2.00.0050.00917.98
8.1.280.0330.01325.92
8.1.270.0130.00723.92
8.1.260.0060.00626.35
8.1.250.0060.00628.09
8.1.240.0070.00323.82
8.1.230.0140.00919.16
8.1.220.0150.00017.79
8.1.210.0000.00818.77
8.1.200.0030.00717.35
8.1.190.0100.00517.52
8.1.180.0030.00618.10
8.1.170.0000.00918.57
8.1.160.0050.01122.04
8.1.150.0040.00418.73
8.1.140.0080.00017.41
8.1.130.0040.00417.93
8.1.120.0000.01517.59
8.1.110.0080.00817.55
8.1.100.0000.00917.58
8.1.90.0050.00517.54
8.1.80.0000.01517.54
8.1.70.0040.00417.50
8.1.60.0000.00817.55
8.1.50.0030.00517.61
8.1.40.0100.00717.50
8.1.30.0060.00317.62
8.1.20.0000.00817.74
8.1.10.0030.00617.68
8.1.00.0070.00317.66
8.0.300.0080.00418.77
8.0.290.0160.00017.05
8.0.280.0160.00018.30
8.0.270.0030.00617.27
8.0.260.0100.00316.83
8.0.250.0050.01016.87
8.0.240.0050.00516.95
8.0.230.0000.01016.87
8.0.220.0050.00516.84
8.0.210.0000.01416.89
8.0.200.0070.00716.77
8.0.190.0030.00716.80
8.0.180.0040.00716.90
8.0.170.0040.00416.82
8.0.160.0090.00016.85
8.0.150.0070.00016.86
8.0.140.0050.00316.88
8.0.130.0040.00413.37
8.0.120.0060.00316.85
8.0.110.0040.00416.83
8.0.100.0000.01416.92
8.0.90.0000.00816.69
8.0.80.0030.01616.80
8.0.70.0030.00616.75
8.0.60.0050.01016.87
8.0.50.0040.00416.89
8.0.30.0180.01217.19
8.0.20.0260.01517.40
8.0.10.0000.00817.04
8.0.00.0250.01416.85
7.4.330.0110.00415.03
7.4.320.0050.01016.44
7.4.300.0040.00416.39
7.4.290.0140.00016.52
7.4.280.0030.00616.39
7.4.270.0070.00016.41
7.4.260.0060.00316.31
7.4.250.0080.00416.36
7.4.240.0070.00716.44
7.4.230.0080.00816.39
7.4.220.0160.01216.45
7.4.210.0140.01716.50
7.4.200.0040.00416.34
7.4.190.0030.00616.49
7.4.160.0180.00316.52
7.4.150.0280.02717.40
7.4.140.0260.01917.86
7.4.130.0180.01016.48
7.4.120.0280.01616.49
7.4.110.0200.00316.46
7.4.100.1070.02016.32
7.4.90.0950.03916.47
7.4.80.0800.02016.40
7.4.70.0280.01116.63
7.4.60.0140.00416.57
7.4.50.0050.00516.59
7.4.40.0100.01022.77
7.4.30.0380.04616.43
7.4.00.0100.00715.01
7.3.330.0031.99913.30
7.3.320.0231.99113.30
7.3.310.0040.00416.23
7.3.300.0070.00716.42
7.3.290.0070.01416.31
7.3.280.0120.01116.36
7.3.270.0110.00917.40
7.3.260.0140.00716.44
7.3.250.0460.01716.45
7.3.240.0110.00816.28
7.3.230.1110.04116.39
7.3.210.0350.01516.36
7.3.200.0150.01119.39
7.3.190.0680.02216.54
7.3.180.0100.01316.45
7.3.170.0870.02416.27
7.3.160.0720.02916.34
7.3.120.0100.00714.61
7.2.330.0410.01316.70
7.2.320.0140.01416.48
7.2.310.0130.01316.66
7.2.300.0660.02716.53
7.2.290.0210.01916.73
7.2.60.0090.00916.82
7.1.200.0060.01115.87
7.1.70.0030.00616.97
7.1.60.0040.01519.29
7.1.50.0040.02217.14
7.1.00.0070.07022.31
7.0.200.0160.00616.81
7.0.140.0070.07022.13
7.0.60.0230.08019.96
7.0.50.0100.07717.82
7.0.40.0170.04719.87
7.0.30.0300.07019.98
7.0.20.0200.04319.83
7.0.10.0230.07719.88
7.0.00.0000.05019.82
5.6.280.0030.08021.09
5.6.210.0100.08020.53
5.6.200.0100.07718.16
5.6.190.0070.08720.37
5.6.180.3100.04020.48
5.6.170.0470.05020.41
5.6.160.0070.06720.33
5.6.150.0130.07018.18
5.6.140.0100.08018.15
5.6.130.0070.04018.20
5.6.120.0130.08021.03
5.6.110.0130.07321.03
5.6.100.0130.07721.15
5.6.90.0170.07721.14
5.6.80.0070.07720.50
5.5.350.0170.07720.44
5.5.340.0130.06020.80
5.5.330.0030.04320.29
5.5.320.0270.07020.05
5.5.310.0200.05020.74
5.5.300.0100.08717.81
5.5.290.0070.05717.97
5.5.280.0100.07720.85
5.5.270.0070.07720.95
5.5.260.0100.07720.86
5.5.250.0070.08320.63
5.5.240.0100.04720.25
5.4.450.0330.05019.36
5.4.440.0300.07019.38
5.4.430.0170.04719.39
5.4.420.0270.08319.36
5.4.410.0370.05719.18
5.4.400.0200.03319.09
5.4.390.0070.05719.08
5.4.380.0200.05019.08
5.4.370.0330.05718.95
5.4.360.0170.05019.03
5.4.350.0230.05019.27
5.4.340.0100.06318.85
5.4.320.0170.05019.12
5.4.310.0530.05318.80
5.4.300.0330.07318.95
5.4.290.0130.05018.86
5.4.280.0570.06719.03
5.4.270.0130.06319.04
5.4.260.0070.05719.07
5.4.250.0270.04018.89
5.4.240.0330.07319.07
5.4.230.0270.04719.18
5.4.220.0130.05719.07
5.4.210.0170.07019.03
5.4.200.0070.05319.11
5.4.190.0230.05718.80
5.4.180.0270.07019.03
5.4.170.0230.06719.26
5.4.160.0170.08719.05
5.4.150.4500.05318.94
5.4.140.3470.03016.64
5.4.130.0130.03716.48
5.4.120.0070.06316.57
5.4.110.0170.04316.29
5.4.100.0130.04016.41
5.4.90.0170.03716.56
5.4.80.0030.03716.57
5.4.70.0300.03016.48
5.4.60.0030.08016.43
5.4.50.0070.07016.52
5.4.40.0130.06716.52
5.4.30.0300.05016.25
5.4.20.0300.06316.24
5.4.10.0200.03716.22
5.4.00.3770.03715.96
5.3.290.3400.04015.82
5.3.280.4000.03714.97
5.3.270.3800.03315.84
5.3.260.2770.03014.53
5.3.250.1400.04314.58
5.3.240.0170.04014.66
5.3.230.0330.07014.61
5.3.220.3500.03714.65
5.3.210.0300.04314.59
5.3.200.0130.04714.68
5.3.190.0230.03314.65
5.3.180.0270.07714.54
5.3.170.0270.04314.48
5.3.160.0600.04314.49
5.3.150.0570.03014.49
5.3.140.0530.05714.55
5.3.130.3770.03314.47
5.3.120.0600.04714.60
5.3.110.0330.04014.56
5.3.100.3630.03014.06
5.3.90.0430.03014.11
5.3.80.0670.02713.93
5.3.70.0500.05714.16
5.3.60.0430.06714.01
5.3.50.0400.03314.09
5.3.40.0470.02713.84
5.3.30.0370.03714.13
5.3.20.0330.04313.71
5.3.10.0530.05313.52
5.3.00.0400.02713.78
5.2.170.0370.04711.84
5.2.160.0370.05711.86
5.2.150.2570.03011.88
5.2.140.3100.03011.87
5.2.130.0370.03311.88
5.2.120.0470.05011.88
5.2.110.0400.04311.88
5.2.100.0470.02711.85
5.2.90.0400.04311.85
5.2.80.0030.06311.84
5.2.70.0100.04011.83
5.2.60.0400.05311.87
5.2.50.2670.02711.86
5.2.40.0430.05011.82
5.2.30.0300.05711.85
5.2.20.0370.05011.85
5.2.10.0400.04711.82
5.2.00.0400.05011.88
5.1.60.0330.02711.88
5.1.50.0000.02311.88
5.1.40.0030.05313.81
5.1.30.0030.06013.88
5.1.20.0100.02313.86
5.1.10.0370.05713.88
5.1.00.0330.02313.77
5.0.50.0200.04013.88
5.0.40.0270.03313.88
5.0.30.0200.05713.88
5.0.20.0130.02013.83
5.0.10.0070.02013.88
5.0.00.0230.05313.84
4.4.90.0000.02313.88
4.4.80.0000.01713.88
4.4.70.0030.02713.84
4.4.60.0030.01713.78
4.4.50.0000.03713.91
4.4.40.0000.03313.88
4.4.30.0100.03713.80
4.4.20.0070.03713.87
4.4.10.0100.02313.91
4.4.00.0100.04713.87
4.3.110.0130.03313.88
4.3.100.0100.03313.91
4.3.90.0030.01713.91
4.3.80.0000.05713.90
4.3.70.0170.03013.91
4.3.60.1600.01713.88
4.3.50.1630.01313.85
4.3.40.1230.02013.91
4.3.30.0670.01713.91
4.3.20.0570.01313.91
4.3.10.0030.02013.91
4.3.00.0030.01713.91

preferences:
56.26 ms | 401 KiB | 5 Q