3v4l.org

run code in 300+ PHP versions simultaneously
<?php function numberToRoman(int $integer): string { static $conversions = [ 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD', 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL', 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I' ]; $romanString = ''; foreach ($conversions as $int => $roman) { echo "\tcheck $roman\n"; while ($integer >= $int) { echo "\tsubtract $int\n"; $romanString .= $roman; if (!($integer -= $int)) { break 2; } } } return $romanString; } echo numberToRoman(3333); echo "\n---\n"; echo numberToRoman(5000); echo "\n======\n"; function numberToRomanRepresentation($number) { $map = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); $returnValue = ''; while ($number > 0) { foreach ($map as $roman => $int) { echo "\tcheck $roman\n"; if($number >= $int) { echo "\tsubtract $int\n"; $number -= $int; $returnValue .= $roman; break; } } } return $returnValue; } echo numberToRomanRepresentation(3333); echo "\n---\n"; echo numberToRomanRepresentation(5000);

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.4.140.0120.01017.67
8.4.130.0110.01017.91
8.4.120.0100.01120.46
8.4.110.0150.00720.39
8.4.100.0060.00518.74
8.4.90.0120.00920.54
8.4.80.0120.00918.81
8.4.70.0130.00718.02
8.4.60.0100.00618.65
8.4.50.0060.00318.89
8.4.40.0100.00719.56
8.4.30.0190.00018.59
8.4.20.0100.00317.57
8.4.10.0100.00021.93
8.3.270.0170.00416.61
8.3.260.0130.00716.78
8.3.250.0100.00918.97
8.3.240.0090.01116.55
8.3.230.0150.00516.57
8.3.220.0110.00718.98
8.3.210.0100.00516.86
8.3.200.0080.00216.38
8.3.190.0070.01216.93
8.3.180.0030.00516.85
8.3.170.0110.00719.12
8.3.160.0130.00620.09
8.3.150.0100.01016.80
8.3.140.0130.00316.79
8.3.130.0110.00016.61
8.3.120.0100.00620.80
8.3.110.0040.00416.74
8.3.100.0070.00316.56
8.3.90.0110.00726.77
8.3.80.0060.00316.50
8.3.70.0200.00316.58
8.3.60.0040.01218.43
8.3.50.0130.00619.93
8.3.40.0120.00920.39
8.3.30.0060.00918.85
8.3.20.0050.00224.18
8.3.10.0000.00824.66
8.3.00.0000.00826.16
8.2.290.0060.00520.27
8.2.280.0100.00918.30
8.2.270.0030.00617.24
8.2.260.0120.00318.09
8.2.250.0150.00316.55
8.2.240.0060.00318.86
8.2.230.0030.00620.94
8.2.220.0030.01424.06
8.2.210.0040.00426.77
8.2.200.0100.00018.16
8.2.190.0070.00716.88
8.2.180.0100.00725.92
8.2.170.0070.01019.00
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0040.00421.04
8.2.110.0060.00321.00
8.2.100.0060.00617.84
8.2.90.0040.00417.88
8.2.80.0060.00318.77
8.2.70.0080.00017.50
8.2.60.0040.00417.75
8.2.50.0030.00517.98
8.2.40.0000.00818.28
8.2.30.0030.00618.20
8.2.20.0040.00419.41
8.2.10.0040.00418.25
8.2.00.0040.00419.34
8.1.330.0140.00521.82
8.1.320.0130.00715.98
8.1.310.0110.00718.68
8.1.300.0200.00016.07
8.1.290.0000.00930.84
8.1.280.0140.00725.92
8.1.270.0040.00424.66
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00723.86
8.1.230.0030.00922.73
8.1.220.0030.00618.51
8.1.210.0030.00518.77
8.1.200.0040.00417.36
8.1.190.0030.00517.13
8.1.180.0060.00318.10
8.1.170.0060.00217.62
8.1.160.0040.00418.86
8.1.150.0040.00418.70
8.1.140.0040.00417.39
8.1.130.0030.00318.95
8.1.120.0080.00017.49
8.1.110.0070.00017.39
8.1.100.0130.00517.50
8.1.90.0100.00317.50
8.1.80.0090.00917.38
8.1.70.0050.00517.52
8.1.60.0150.00317.61
8.1.50.0160.00317.41
8.1.40.0100.00817.50
8.1.30.0090.00917.59
8.1.20.0100.00717.60
8.1.10.0100.00717.47
8.1.00.0160.00217.48
8.0.300.0000.00919.98
8.0.290.0080.00016.75
8.0.280.0050.00318.47
8.0.270.0040.00416.77
8.0.260.0030.00618.41
8.0.250.0030.00316.97
8.0.240.0000.00816.84
8.0.230.0120.00316.94
8.0.220.0050.01016.86
8.0.210.0110.00316.78
8.0.200.0080.00816.84
8.0.190.0070.00716.93
8.0.180.0120.00416.89
8.0.170.0000.01516.98
8.0.160.0130.00216.88
8.0.150.0100.00616.77
8.0.140.0070.01016.78
8.0.130.0100.00516.68
8.0.120.0100.00516.85
8.0.110.0150.00016.91
8.0.100.0150.00216.82
8.0.90.0080.00816.87
8.0.80.0090.00616.80
8.0.70.0130.00216.98
8.0.60.0150.00016.72
8.0.50.0000.01616.76
8.0.30.0100.00516.84
8.0.20.0110.00416.94
8.0.10.0140.00017.00
7.4.330.0080.00015.55
7.4.320.0060.00016.63
7.4.300.0090.00416.40
7.4.290.0130.00016.65
7.4.280.0090.00316.63
7.4.270.0110.00216.61
7.4.260.0060.00616.49
7.4.250.0110.00016.49
7.4.240.0110.00316.59
7.4.230.0100.00716.41
7.4.220.0070.00716.43
7.4.210.0130.00016.50
7.4.200.0040.00416.59
7.4.190.0070.00616.52
7.4.180.0040.00816.49
7.4.160.0050.00716.43
7.4.150.0080.00316.60
7.4.140.0080.00316.36
7.4.130.0090.00316.46
7.4.120.0000.01016.46
7.4.110.0080.00316.50
7.4.100.0110.00316.37
7.4.90.0130.00316.45
7.4.80.0100.00216.32
7.4.70.0100.00316.43
7.4.60.0110.00016.39
7.4.50.0140.00016.24
7.4.40.0140.00016.35
7.4.30.0070.00716.39
7.4.20.0110.00316.43
7.4.10.0110.00316.50
7.4.00.0090.00616.46

preferences:
29.51 ms | 403 KiB | 5 Q