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'; /** * @return array * @author Josh Di Fabio <joshdifabio@hotmail.com> */ public static function getIntegerToNumeralMap() { return array( 1 => RomanNumeral::ONE, 4 => RomanNumeral::FOUR, 5 => RomanNumeral::FIVE, 9 => RomanNumeral::NINE, 10 => RomanNumeral::TEN, 40 => RomanNumeral::FOURTY, 50 => RomanNumeral::FIFTY, 90 => RomanNumeral::NINETY, 100 => RomanNumeral::ONE_HUNDRED, 400 => RomanNumeral::FOUR_HUNDRED, 500 => RomanNumeral::FIVE_HUNDRED, 900 => RomanNumeral::NINE_HUNDRED, 1000 => RomanNumeral::ONE_THOUSAND, ); } } class RomanNumeralGenerator implements 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) { 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.'); } $numeralString = ''; $integerToNumeralMap = RomanNumeral::getIntegerToNumeralMap(); krsort($integerToNumeralMap); while (0 < $number) { foreach ($integerToNumeralMap as $_integer => $_numeral) { /* * if the input number less any already selected numerals is larger than the current * numeral, select the current numeral and deduct its integer value from the input * number */ if ($number >= $_integer) { $numeralString .= $_numeral; $number -= $_integer; break; } } } return $numeralString; } } $generator = new RomanNumeralGenerator; echo $generator->generate(0);

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.0090.01218.35
8.3.50.0150.00717.38
8.3.40.0120.00918.75
8.3.30.0090.00618.65
8.3.20.0040.00418.95
8.3.10.0090.00020.71
8.3.00.0060.00317.38
8.2.180.0150.00316.88
8.2.170.0040.01122.96
8.2.160.0100.00322.25
8.2.150.0000.00825.66
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0050.00319.89
8.2.110.0090.00022.08
8.2.100.0040.00717.84
8.2.90.0110.00020.95
8.2.80.0040.00418.04
8.2.70.0050.00317.50
8.2.60.0040.00417.91
8.2.50.0000.00818.07
8.2.40.0020.00518.22
8.2.30.0000.00718.16
8.2.20.0030.00617.88
8.2.10.0050.00517.70
8.2.00.0030.00617.80
8.1.280.0070.00725.92
8.1.270.0000.00824.66
8.1.260.0000.00726.35
8.1.250.0070.00028.09
8.1.240.0060.00317.78
8.1.230.0070.00420.71
8.1.220.0040.00417.74
8.1.210.0040.00419.02
8.1.200.0060.00617.35
8.1.190.0040.00417.53
8.1.180.0000.00818.10
8.1.170.0030.00518.90
8.1.160.0070.00018.87
8.1.150.0050.00318.76
8.1.140.0040.00417.37
8.1.130.0040.00417.91
8.1.120.0050.00317.52
8.1.110.0030.00617.38
8.1.100.0040.00417.54
8.1.90.0000.00717.46
8.1.80.0000.00717.54
8.1.70.0030.00517.39
8.1.60.0040.00417.66
8.1.50.0040.00417.55
8.1.40.0040.00417.48
8.1.30.0000.00717.70
8.1.20.0050.00317.61
8.1.10.0040.00417.52
8.1.00.0000.00917.41
8.0.300.0040.00420.16
8.0.290.0030.00616.88
8.0.280.0000.00718.43
8.0.270.0050.00217.25
8.0.260.0000.00718.50
8.0.250.0040.00417.05
8.0.240.0060.00316.96
8.0.230.0000.00717.08
8.0.220.0000.00716.89
8.0.210.0040.00416.96
8.0.200.0040.00817.08
8.0.190.0030.00617.07
8.0.180.0030.00517.02
8.0.170.0050.00316.91
8.0.160.0040.00417.13
8.0.150.0040.00417.02
8.0.140.0060.00616.82
8.0.130.0030.00313.44
8.0.120.0000.00716.84
8.0.110.0000.00716.78
8.0.100.0040.00417.07
8.0.90.0050.00217.03
8.0.80.0040.01116.88
8.0.70.0030.00516.92
8.0.60.0040.00417.12
8.0.50.0000.00716.96
8.0.30.0080.01117.18
8.0.20.0060.01217.25
8.0.10.0000.00717.17
8.0.00.0080.01016.75
7.4.330.0030.00313.03
7.4.320.0030.00316.69
7.4.300.0070.00016.59
7.4.290.0000.00716.44
7.4.280.0000.00816.65
7.4.270.0000.00816.65
7.4.260.0000.00613.26
7.4.250.0040.00416.46
7.4.240.0000.00716.56
7.4.230.0000.00716.68
7.4.220.0090.01516.43
7.4.210.0070.00716.66
7.4.200.0000.00816.75
7.4.190.0030.00316.59
7.4.160.0080.00816.66
7.4.150.0060.01316.76
7.4.140.0100.01016.73
7.4.130.0100.00716.56
7.4.120.0090.00816.53
7.4.110.0130.01016.58
7.4.100.0100.01316.63
7.4.90.0080.01116.58
7.4.80.0090.00916.41
7.4.70.0030.01316.62
7.4.60.0110.00416.74
7.4.50.0000.00416.29
7.4.40.0030.00916.39
7.4.30.0150.00616.70
7.4.00.0060.00914.71
7.3.330.0030.00313.41
7.3.320.0060.00013.33
7.3.310.0030.00316.30
7.3.300.0000.00716.44
7.3.290.0090.00616.39
7.3.280.0080.01016.39
7.3.270.0110.00716.47
7.3.260.0100.01316.38
7.3.250.0110.01416.48
7.3.240.0080.00816.46
7.3.230.0140.00316.53
7.3.210.0070.01016.36
7.3.200.0120.00619.39
7.3.190.0110.01116.51
7.3.180.0060.00916.55
7.3.170.0060.01916.44
7.3.160.0120.00416.49
7.3.120.0060.00914.95
7.2.330.0060.01216.65
7.2.320.0070.01516.47
7.2.310.0100.01316.80
7.2.300.0070.01016.54
7.2.290.0100.00716.52
7.2.110.0680.00316.67
7.2.60.0070.00716.95
7.2.00.0130.00319.02
7.1.200.0070.00715.70
7.1.100.0040.01117.92
7.1.70.0020.00516.97
7.1.60.0090.01519.40
7.1.50.0080.00317.10
7.1.00.0000.06322.48
7.0.200.0000.00716.82
7.0.140.0100.06721.95
7.0.120.0100.05022.04
7.0.60.0000.04320.07
7.0.50.0200.05317.90
7.0.40.0100.05317.86
7.0.30.0030.06317.75
7.0.20.0070.09017.86
7.0.10.0030.08017.72
7.0.00.0030.04317.68
5.6.210.0100.06320.63
5.6.200.0100.03718.28
5.6.190.0100.04718.27
5.6.180.0070.08318.21
5.6.170.0200.07318.13
5.6.160.0100.08018.18
5.6.150.0130.06018.18
5.6.140.0130.06318.18
5.6.130.0070.04718.28
5.6.120.0100.03718.13
5.6.110.0100.05018.15
5.6.100.0100.06718.23
5.6.90.0030.05718.15
5.6.80.0070.06717.56
5.6.70.0030.07717.52
5.6.60.0100.06017.59
5.6.50.0000.06317.56
5.6.40.0100.07317.49
5.6.30.0100.07317.54
5.6.20.0100.07317.54
5.6.10.0070.06717.53
5.6.00.0070.05717.63
5.5.350.0030.08020.31
5.5.340.0070.04718.00
5.5.330.0100.08018.01
5.5.320.0100.07717.98
5.5.310.0070.08017.92
5.5.300.0070.07717.96
5.5.290.0070.05018.06
5.5.280.0000.04717.99
5.5.270.0100.07717.95
5.5.260.0070.05318.10
5.5.250.0000.04317.79
5.5.240.0130.03717.34
5.5.230.0030.04017.34
5.5.220.0100.04017.33
5.5.210.0030.05017.34
5.5.200.0170.06717.45
5.5.190.0100.07317.34
5.5.180.0000.08317.39
5.5.160.0070.08017.34
5.5.150.0030.04317.30
5.5.140.0100.07317.34
5.5.130.0130.04017.39
5.5.120.0130.06317.43
5.5.110.0070.04317.36
5.5.100.0070.07317.25
5.5.90.0130.05717.21
5.5.80.0070.07717.29
5.5.70.0030.04317.20
5.5.60.0070.07317.18
5.5.50.0170.06317.23
5.5.40.0030.06317.25
5.5.30.0130.05717.19
5.5.20.0070.04317.22
5.5.10.0170.06017.28
5.5.00.0230.04017.21
5.4.450.0070.04019.45
5.4.440.0100.07719.41
5.4.430.0100.05019.32
5.4.420.0070.07719.30
5.4.410.0130.04719.24
5.4.400.0130.07318.95
5.4.390.0070.04719.04
5.4.380.0000.04019.27
5.4.370.0130.05719.26
5.4.360.0070.07719.01
5.4.350.0100.07319.02
5.4.340.0030.08319.13
5.4.320.0030.05018.97
5.4.310.0070.03719.05
5.4.300.0170.05019.01
5.4.290.0030.08019.26
5.4.280.0100.07019.01
5.4.270.0100.07019.11
5.4.260.0030.07319.27
5.4.250.0070.06019.13
5.4.240.0000.08019.08
5.4.230.0070.04019.02
5.4.220.0070.05719.04
5.4.210.0130.04319.02
5.4.200.0000.05019.02
5.4.190.0030.07719.11
5.4.180.0030.03719.11
5.4.170.0130.05019.04
5.4.160.0070.03719.07
5.4.150.0030.05719.01
5.4.140.0100.07716.39
5.4.130.0170.06016.36
5.4.120.0070.07716.43
5.4.110.0070.05316.40
5.4.100.0070.08016.47
5.4.90.0130.05716.45
5.4.80.0200.06016.58
5.4.70.0130.06316.27
5.4.60.0000.07716.38
5.4.50.0130.06016.38
5.4.40.0130.07016.46
5.4.30.0100.05316.40
5.4.20.0130.05716.30
5.4.10.0070.07716.40
5.4.00.0100.05715.82
5.3.290.0070.03714.74
5.3.280.0030.05014.57
5.3.270.0030.04014.64
5.3.260.0130.07014.57
5.3.250.0030.07014.67
5.3.240.0170.05314.49
5.3.230.0070.04714.66
5.3.220.0030.06014.63
5.3.210.0070.08014.58
5.3.200.0100.05314.43
5.3.190.0100.06014.54
5.3.180.0030.04314.64
5.3.170.0030.05314.63
5.3.160.0070.06014.66
5.3.150.0070.07014.59
5.3.140.0070.05014.62
5.3.130.0200.06714.56
5.3.120.0100.04714.59
5.3.110.0130.07014.55
5.3.100.0070.06314.14
5.3.90.0070.04714.06
5.3.80.0200.05314.07
5.3.70.0000.04714.06
5.3.60.0030.07714.21
5.3.50.0100.03314.06
5.3.40.0070.03713.98
5.3.30.0030.03713.92
5.3.20.0030.04013.71
5.3.10.0100.03713.72
5.3.00.0100.04013.68
5.2.170.0030.05011.06
5.2.160.0000.03311.11
5.2.150.0000.03311.17
5.2.140.0070.04711.04
5.2.130.0030.03010.95
5.2.120.0130.05711.24
5.2.110.0030.06010.93
5.2.100.0070.06311.04
5.2.90.0100.05011.09
5.2.80.0100.04710.98
5.2.70.0030.03710.99
5.2.60.0070.04011.04
5.2.50.0100.05710.94
5.2.40.0000.06010.94
5.2.30.0030.04010.87
5.2.20.0030.06310.91
5.2.10.0030.05010.88
5.2.00.0070.04710.72
5.1.60.0070.0279.97
5.1.50.0000.0339.93
5.1.40.0000.0379.96
5.1.30.0030.05010.31
5.1.20.0000.06010.20
5.1.10.0100.03010.10
5.1.00.0000.03310.05
5.0.50.0070.0438.38
5.0.40.0000.0378.37
5.0.30.0070.0538.20
5.0.20.0030.0208.26
5.0.10.0000.0238.24
5.0.00.0100.0338.14
4.4.90.0030.0207.49
4.4.80.0030.0377.49
4.4.70.0000.0277.49
4.4.60.0000.0307.49
4.4.50.0030.0207.49
4.4.40.0030.0337.49
4.4.30.0000.0177.49
4.4.20.0030.0277.49
4.4.10.0000.0377.49
4.4.00.0000.0577.49
4.3.110.0030.0207.49
4.3.100.0000.0207.49
4.3.90.0030.0377.49
4.3.80.0000.0337.49
4.3.70.0000.0207.49
4.3.60.0000.0177.49
4.3.50.0000.0177.49
4.3.40.0000.0577.49
4.3.30.0000.0237.49
4.3.20.0030.0177.49
4.3.10.0000.0177.49
4.3.00.0000.0207.49

preferences:
43.57 ms | 401 KiB | 5 Q