3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace JoshDiFabio; interface RomanNumeralGeneratorInterface { /** * @param int $number * @return string * @throws \InvalidArgumentException Argument not an integer or out of range * @author Josh Di Fabio <joshdifabio@hotmail.com> */ public function generate($number); } class RomanNumeral { const ONE = 'I'; const FOUR = 'IV'; const FIVE = 'V'; const NINE = 'IX'; const TEN = 'X'; const FOURTY = 'XL'; const FIFTY = 'L'; const NINETY = 'XC'; const ONE_HUNDRED = 'C'; const FOUR_HUNDRED = 'CD'; const FIVE_HUNDRED = 'D'; const NINE_HUNDRED = 'CM'; const ONE_THOUSAND = 'M'; } class RomanNumeralGenerator implements RomanNumeralGeneratorInterface { /** * @var array * @author Josh Di Fabio <joshdifabio@hotmail.com> */ private $_integerNumeralMap = array( 1000 => RomanNumeral::ONE_THOUSAND, 900 => RomanNumeral::NINE_HUNDRED, 500 => RomanNumeral::FIVE_HUNDRED, 400 => RomanNumeral::FOUR_HUNDRED, 100 => RomanNumeral::ONE_HUNDRED, 90 => RomanNumeral::NINETY, 50 => RomanNumeral::FIFTY, 40 => RomanNumeral::FOURTY, 10 => RomanNumeral::TEN, 9 => RomanNumeral::NINE, 5 => RomanNumeral::FIVE, 4 => RomanNumeral::FOUR, 1 => RomanNumeral::ONE, ); /** * @param int $number * @return string * @throws \InvalidArgumentException Argument not an integer or out of range * @author Josh Di Fabio <joshdifabio@hotmail.com> */ public function generate($number) { if (!is_integer($number)) { throw new \InvalidArgumentException('Provided argument is not an integer.'); } if (1 > $number || 3999 < $number) { throw new \InvalidArgumentException( 'The provided number is not within the allowed range of 1 to 3999.'); } $numerals = array(); while (0 < $number) { foreach ($this->_integerNumeralMap as $_integer => $_numeral) { /* * if the input number less any already selected numerals is larger than the current * numeral, choose the current numeral and deduct its integer value from the input * number */ if ($number >= $_integer) { $numerals[] = $_numeral; $number -= $_integer; break; } } } return implode('', $numerals); } } $generator = new RomanNumeralGenerator; echo $generator->generate(3999);

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.00018.68
8.3.50.0100.01116.63
8.3.40.0120.00318.90
8.3.30.0110.00418.77
8.3.20.0040.00418.70
8.3.10.0000.00820.41
8.3.00.0000.01117.38
8.2.180.0140.00716.63
8.2.170.0070.00722.96
8.2.160.0140.00322.12
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0080.00019.89
8.2.110.0090.00020.97
8.2.100.0040.00817.91
8.2.90.0050.00319.18
8.2.80.0080.00017.97
8.2.70.0060.00317.48
8.2.60.0080.00017.93
8.2.50.0000.00818.07
8.2.40.0040.00418.22
8.2.30.0070.00318.25
8.2.20.0040.00417.83
8.2.10.0040.00417.86
8.2.00.0090.00017.72
8.1.280.0100.00725.92
8.1.270.0000.00823.99
8.1.260.0080.00026.35
8.1.250.0090.00028.09
8.1.240.0060.00321.33
8.1.230.0040.00817.45
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0000.00817.36
8.1.190.0050.00317.23
8.1.180.0060.00618.10
8.1.170.0040.00418.96
8.1.160.0040.00419.00
8.1.150.0030.00518.71
8.1.140.0000.00817.41
8.1.130.0030.00317.71
8.1.120.0000.00717.41
8.1.110.0000.00717.55
8.1.100.0020.00517.55
8.1.90.0040.00417.44
8.1.80.0000.00817.50
8.1.70.0000.00717.46
8.1.60.0050.00517.64
8.1.50.0080.00017.56
8.1.40.0000.00817.57
8.1.30.0060.00317.69
8.1.20.0050.00317.57
8.1.10.0060.00317.64
8.1.00.0030.00617.45
8.0.300.0090.00018.77
8.0.290.0040.00416.63
8.0.280.0030.00318.50
8.0.270.0070.00017.30
8.0.260.0000.00718.61
8.0.250.0050.00317.01
8.0.240.0040.00416.92
8.0.230.0070.00017.00
8.0.220.0050.00216.86
8.0.210.0040.00416.96
8.0.200.0040.00417.00
8.0.190.0000.00817.07
8.0.180.0050.00216.81
8.0.170.0030.00516.93
8.0.160.0030.00317.00
8.0.150.0050.00316.92
8.0.140.0070.00316.94
8.0.130.0000.00513.41
8.0.120.0000.00716.80
8.0.110.0030.00616.82
8.0.100.0000.00816.88
8.0.90.0030.00516.90
8.0.80.0090.01016.88
8.0.70.0080.00016.98
8.0.60.0000.00716.82
8.0.50.0050.00216.84
8.0.30.0090.01417.36
8.0.20.0100.00917.18
8.0.10.0040.00416.92
8.0.00.0090.01016.89
7.4.330.0060.00014.73
7.4.320.0000.00716.61
7.4.300.0000.00616.61
7.4.290.0030.00516.50
7.4.280.0000.00716.65
7.4.270.0000.00716.53
7.4.260.0000.00613.30
7.4.250.0080.00016.64
7.4.240.0080.00016.64
7.4.230.0000.00716.73
7.4.220.0040.01516.64
7.4.210.0040.01516.59
7.4.200.0020.00516.72
7.4.190.0000.00716.61
7.4.160.0040.01216.53
7.4.150.0210.00617.18
7.4.140.0110.01017.13
7.4.130.0100.01016.59
7.4.120.0060.01116.54
7.4.110.0070.01016.70
7.4.100.0130.00316.49
7.4.90.0120.00616.58
7.4.80.0090.00918.80
7.4.70.0120.00416.45
7.4.60.0180.00316.82
7.4.50.0060.00316.52
7.4.40.0090.00622.27
7.4.30.0070.00716.58
7.4.00.0000.01515.09
7.3.330.0030.00313.36
7.3.320.0030.00313.43
7.3.310.0000.00616.32
7.3.300.0000.00716.40
7.3.290.0070.00716.44
7.3.280.0130.00616.42
7.3.270.0060.01217.18
7.3.260.0110.00718.24
7.3.250.0120.01016.34
7.3.240.0040.01216.43
7.3.230.0110.00616.65
7.3.210.0090.01416.63
7.3.200.0060.01219.39
7.3.190.0140.00316.40
7.3.180.0120.00416.69
7.3.170.0120.01016.54
7.3.160.0090.00616.59
7.3.120.0100.00614.89
7.2.330.0090.00916.81
7.2.320.0130.01016.71
7.2.310.0070.01016.71
7.2.300.0070.01016.90
7.2.290.0060.00916.64
7.2.00.0070.00319.47
7.1.100.0030.01418.24
7.1.70.0000.01117.07
7.1.60.0130.01319.40
7.1.50.0070.01417.05
7.1.00.0030.06322.31
7.0.200.0030.00516.66
7.0.140.0000.08022.02
7.0.60.0130.07319.95
7.0.50.0000.05317.89
7.0.40.0070.07317.86
7.0.30.0130.04317.74
7.0.20.0170.07717.72
7.0.10.0030.05017.73
7.0.00.0030.05017.73
5.6.280.0100.06721.12
5.6.210.0070.04320.70
5.6.200.0070.06018.22
5.6.190.0100.08018.29
5.6.180.0030.08318.29
5.6.170.0070.06718.19
5.6.160.0030.07718.14
5.6.150.0130.07718.25
5.6.140.0030.05018.13
5.6.130.0070.05318.19
5.6.120.0070.04018.28
5.6.110.0130.07318.12
5.6.100.0130.07718.16
5.6.90.0070.05018.16
5.6.80.0000.04017.52
5.6.70.0000.04017.54
5.6.60.0030.03717.64
5.6.50.0070.04017.61
5.6.40.0030.03717.50
5.6.30.0070.03717.55
5.6.20.0000.08317.64
5.6.10.0030.06317.63
5.6.00.0030.04317.62
5.5.350.0030.07720.41
5.5.340.0130.05718.05
5.5.330.0030.05017.96
5.5.320.0100.04718.05
5.5.310.0170.07018.07
5.5.300.0100.06317.95
5.5.290.0130.08318.04
5.5.280.0000.06718.08
5.5.270.0100.04717.95
5.5.260.0070.06717.96
5.5.250.0000.04317.81
5.5.240.0030.03717.34
5.5.230.0130.02717.32
5.5.220.0030.03717.41
5.5.210.0070.03317.31
5.5.200.0100.03317.45
5.5.190.0070.06317.40
5.5.180.0030.06317.43
5.5.160.0000.04017.28
5.5.150.0030.03717.43
5.5.140.0070.05317.43
5.5.130.0000.04017.28
5.5.120.0030.04017.30
5.5.110.0070.03717.32
5.5.100.0030.03717.20
5.5.90.0130.02717.29
5.5.80.0070.03317.32
5.5.70.0030.03717.32
5.5.60.0030.03717.32
5.5.50.0130.03017.23
5.5.40.0070.03317.26
5.5.30.0030.03717.25
5.5.20.0030.03717.19
5.5.10.0030.03717.22
5.5.00.0030.03717.21
5.4.450.0100.04319.32
5.4.440.0100.04019.32
5.4.430.0000.08719.46
5.4.420.0170.06019.21
5.4.410.0030.04019.18
5.4.400.0100.03719.04
5.4.390.0100.03018.99
5.4.380.0070.03319.05
5.4.370.0030.03719.05
5.4.360.0030.03719.03
5.4.350.0000.04719.12
5.4.340.0030.04019.10
5.4.320.0070.03719.10
5.4.310.0000.04019.03
5.4.300.0000.04018.98
5.4.290.0030.04019.05
5.4.280.0000.04019.15
5.4.270.0100.03019.11
5.4.260.0000.04019.10
5.4.250.0070.03319.13
5.4.240.0000.04018.88
5.4.230.0030.03719.08
5.4.220.0030.03719.09
5.4.210.0100.03019.12
5.4.200.0030.03718.95
5.4.190.0000.04019.11
5.4.180.0030.03718.98
5.4.170.0030.05319.08
5.4.160.0100.03019.09
5.4.150.0070.07719.04
5.4.140.0000.06316.38
5.4.130.0100.05716.39
5.4.120.0100.04716.43
5.4.110.0030.07716.64
5.4.100.0070.04316.46
5.4.90.0000.06716.43
5.4.80.0030.07316.44
5.4.70.0070.06316.44
5.4.60.0170.07016.46
5.4.50.0130.03716.43
5.4.40.0070.07716.62
5.4.30.0030.07716.41
5.4.20.0030.06716.42
5.4.10.0100.07316.52
5.4.00.0100.07315.74
5.3.290.0000.04014.68
5.3.280.0000.04014.61
5.3.270.0100.05014.67
5.3.260.0000.04714.62
5.3.250.0070.05314.66
5.3.240.0030.07014.64
5.3.230.0070.06014.62
5.3.220.0070.05014.68
5.3.210.0030.08014.54
5.3.200.0030.06314.57
5.3.190.0070.06314.54
5.3.180.0030.05314.59
5.3.170.0030.08014.79
5.3.160.0070.04014.67
5.3.150.0000.08014.61
5.3.140.0030.08014.59
5.3.130.0130.07314.62
5.3.120.0170.06014.60
5.3.110.0070.07314.59
5.3.100.0030.08014.09
5.3.90.0030.04314.05
5.3.80.0030.08013.87
5.3.70.0070.07313.92
5.3.60.0100.07014.04
5.3.50.0100.06714.16
5.3.40.0070.06714.00
5.3.30.0070.05013.98
5.3.20.0030.07713.74
5.3.10.0100.06013.70
5.3.00.0100.06713.68
5.2.170.0030.06311.09
5.2.160.0030.03311.09
5.2.150.0070.06311.17
5.2.140.0030.05011.28
5.2.130.0000.03011.13
5.2.120.0070.06011.06
5.2.110.0030.03311.13
5.2.100.0070.05311.09
5.2.90.0070.06011.04
5.2.80.0070.04011.06
5.2.70.0000.03310.87
5.2.60.0100.05310.88
5.2.50.0000.06010.80
5.2.40.0030.05710.92
5.2.30.0030.04010.97
5.2.20.0030.06310.86
5.2.10.0070.06010.88
5.2.00.0070.04710.61
5.1.60.0070.0509.96
5.1.50.0100.0409.96
5.1.40.0030.05310.01
5.1.30.0070.05310.33
5.1.20.0030.05710.27
5.1.10.0070.05010.14
5.1.00.0100.05010.11
5.0.50.0030.0378.53
5.0.40.0030.0438.41
5.0.30.0070.0578.25
5.0.20.0030.0478.26
5.0.10.0070.0408.21
5.0.00.0000.0678.22
4.4.90.0000.0377.81
4.4.80.0030.0377.81
4.4.70.0030.0207.81
4.4.60.0030.0177.81
4.4.50.0000.0377.81
4.4.40.0030.0577.81
4.4.30.0030.0307.81
4.4.20.0070.0337.81
4.4.10.0030.0337.81
4.4.00.0030.0307.81
4.3.110.0070.0207.81
4.3.100.0100.0307.81
4.3.90.0030.0377.81
4.3.80.0030.0277.81
4.3.70.0030.0177.81
4.3.60.0070.0237.81
4.3.50.0030.0237.81
4.3.40.0030.0537.81
4.3.30.0000.0307.81
4.3.20.0000.0237.81
4.3.10.0000.0377.81
4.3.00.0030.0307.81

preferences:
43.97 ms | 401 KiB | 5 Q