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(4000);

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.00618.20
8.3.50.0170.00521.14
8.3.40.0070.00718.59
8.3.30.0070.00718.84
8.3.20.0080.00018.81
8.3.10.0000.00820.81
8.3.00.0040.00423.65
8.2.180.0150.00016.63
8.2.170.0120.00322.96
8.2.160.0100.00320.39
8.2.150.0060.00924.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0040.00420.78
8.2.110.0070.00320.60
8.2.100.0110.00017.72
8.2.90.0000.00819.20
8.2.80.0030.00617.97
8.2.70.0000.00817.50
8.2.60.0080.00018.04
8.2.50.0050.00518.07
8.2.40.0080.00018.22
8.2.30.0050.00321.28
8.2.20.0040.00417.81
8.2.10.0000.00817.78
8.2.00.0040.00417.67
8.1.280.0030.01725.92
8.1.270.0040.00423.99
8.1.260.0110.00426.35
8.1.250.0050.00228.09
8.1.240.0100.01022.50
8.1.230.0000.01220.93
8.1.220.0030.00618.77
8.1.210.0040.00418.89
8.1.200.0110.00017.36
8.1.190.0080.00017.53
8.1.180.0050.00318.10
8.1.170.0030.00518.68
8.1.160.0000.00718.85
8.1.150.0040.00418.59
8.1.140.0080.00017.54
8.1.130.0050.00217.87
8.1.120.0050.00317.41
8.1.110.0040.00417.46
8.1.100.0040.00417.41
8.1.90.0050.00317.56
8.1.80.0000.00817.43
8.1.70.0030.00317.53
8.1.60.0000.00817.63
8.1.50.0050.00317.53
8.1.40.0030.00517.60
8.1.30.0040.00417.68
8.1.20.0000.00917.69
8.1.10.0080.00017.63
8.1.00.0050.00517.57
8.0.300.0000.00720.15
8.0.290.0040.00416.89
8.0.280.0070.00018.41
8.0.270.0000.00717.35
8.0.260.0040.00416.88
8.0.250.0000.00717.05
8.0.240.0050.00316.96
8.0.230.0040.00417.13
8.0.220.0040.00316.98
8.0.210.0000.00717.00
8.0.200.0030.00317.05
8.0.190.0030.00516.99
8.0.180.0000.00717.02
8.0.170.0000.00816.94
8.0.160.0000.00716.90
8.0.150.0000.00716.98
8.0.140.0000.00717.03
8.0.130.0030.00313.39
8.0.120.0000.00717.07
8.0.110.0000.00716.99
8.0.100.0040.00416.88
8.0.90.0080.00016.98
8.0.80.0030.01016.88
8.0.70.0070.00017.03
8.0.60.0040.00416.83
8.0.50.0030.00517.03
8.0.30.0060.01317.21
8.0.20.0070.01217.40
8.0.10.0000.00716.99
8.0.00.0110.00716.75
7.4.330.0050.00014.66
7.4.320.0050.00216.45
7.4.300.0000.00716.46
7.4.290.0030.00316.63
7.4.280.0040.00416.66
7.4.270.0070.00016.46
7.4.260.0050.00013.34
7.4.250.0000.00716.52
7.4.240.0070.00016.57
7.4.230.0030.00316.46
7.4.220.0100.01016.63
7.4.210.0060.01016.56
7.4.200.0000.00716.47
7.4.190.0040.00416.45
7.4.160.0160.00616.61
7.4.150.0100.00717.40
7.4.140.0140.00517.86
7.4.130.0070.01416.66
7.4.120.0120.01016.57
7.4.110.0110.00616.55
7.4.100.0070.01016.65
7.4.90.0130.00716.59
7.4.80.0030.01419.39
7.4.70.0090.01216.68
7.4.60.0100.00716.43
7.4.50.0000.00916.49
7.4.40.0070.00722.77
7.4.30.0040.01216.64
7.4.00.0070.00915.20
7.3.330.0000.00613.35
7.3.320.0000.00513.40
7.3.310.0000.00816.29
7.3.300.0030.00316.27
7.3.290.0030.01716.45
7.3.280.0100.00716.41
7.3.270.0090.00917.40
7.3.260.0110.01218.24
7.3.250.0070.00916.52
7.3.240.0100.00716.37
7.3.230.0150.00616.69
7.3.210.0110.01016.25
7.3.200.0070.01019.39
7.3.190.0070.01016.39
7.3.180.0090.00616.60
7.3.170.0070.01016.64
7.3.160.0100.01316.40
7.3.120.0050.01114.83
7.3.110.0030.01015.10
7.3.100.0120.00314.70
7.3.90.0060.00614.96
7.3.80.0070.00715.08
7.3.70.0000.01514.74
7.3.60.0160.00015.01
7.3.50.0090.00914.93
7.3.40.0080.00314.96
7.3.30.0070.00714.56
7.3.20.0070.00316.56
7.3.10.0000.01116.49
7.3.00.0050.00516.81
7.2.330.0130.00616.60
7.2.320.0080.01416.84
7.2.310.0130.01016.75
7.2.300.0130.00516.81
7.2.290.0090.00616.79
7.2.250.0100.00715.07
7.2.240.0030.00715.28
7.2.230.0090.00315.20
7.2.220.0030.01314.84
7.2.210.0000.01815.26
7.2.200.0130.00014.76
7.2.190.0000.01515.07
7.2.180.0070.01014.81
7.2.170.0090.00015.22
7.2.160.0070.00714.96
7.2.150.0090.00016.97
7.2.140.0040.01116.57
7.2.130.0080.00816.63
7.2.120.0070.00716.79
7.2.110.0090.00317.03
7.2.100.0090.00917.02
7.2.90.0080.00817.06
7.2.80.0130.00316.72
7.2.70.0030.01316.97
7.2.60.0030.01316.85
7.2.50.0070.01017.03
7.2.40.0100.00716.97
7.2.30.0030.01016.71
7.2.20.0030.01216.89
7.2.10.0080.00417.13
7.2.00.0050.00918.09
7.1.330.0080.00415.82
7.1.320.0000.01415.93
7.1.310.0080.00415.53
7.1.300.0040.01215.86
7.1.290.0030.01015.90
7.1.280.0070.00715.67
7.1.270.0060.00615.60
7.1.260.0000.01315.52
7.1.250.0070.00715.63
7.1.240.0040.01115.75
7.1.230.0050.00315.78
7.1.220.0080.00615.84
7.1.210.0000.01115.80
7.1.200.0090.00715.71
7.1.190.0100.00315.74
7.1.180.0000.01415.63
7.1.170.0030.01315.57
7.1.160.0100.00615.71
7.1.150.0030.01015.94
7.1.140.0090.00615.82
7.1.130.0070.00715.84
7.1.120.0040.00815.75
7.1.110.0070.00715.85
7.1.100.0030.00916.89
7.1.90.0040.00715.90
7.1.80.0030.01015.79
7.1.70.0070.00716.34
7.1.60.0030.01317.64
7.1.50.0110.00716.44
7.1.40.0030.00615.87
7.1.30.0030.00915.81
7.1.20.0030.01315.92
7.1.10.0060.00615.95
7.1.00.0070.03819.02
7.0.330.0030.00915.50
7.0.320.0030.00815.14
7.0.310.0000.01615.13
7.0.300.0040.01115.19
7.0.290.0060.00915.17
7.0.280.0000.01315.45
7.0.270.0100.00315.54
7.0.260.0030.01015.49
7.0.250.0060.00315.50
7.0.240.0030.00715.53
7.0.230.0000.01715.48
7.0.220.0030.01315.54
7.0.210.0130.00715.47
7.0.200.0060.00616.08
7.0.190.0030.00915.26
7.0.180.0090.00615.23
7.0.170.0040.01215.39
7.0.160.0110.00315.19
7.0.150.0030.01015.48
7.0.140.0050.03618.76
7.0.130.0000.01315.37
7.0.120.0030.01015.20
7.0.110.0060.00615.35
7.0.100.0000.01315.56
7.0.90.0030.00915.46
7.0.80.0030.01015.43
7.0.70.0110.03718.51
7.0.60.0050.03218.53
7.0.50.0070.03118.83
7.0.40.0080.04216.81
7.0.30.0070.04616.69
7.0.20.0090.04216.68
7.0.10.0110.03916.70
7.0.00.0060.03216.74
5.6.400.0090.00314.40
5.6.390.0060.00314.34
5.6.380.0060.01014.37
5.6.370.0130.00314.61
5.6.360.0070.01014.21
5.6.350.0030.01314.34
5.6.340.0060.00614.30
5.6.330.0070.00714.55
5.6.320.0000.00914.16
5.6.310.0030.01314.46
5.6.300.0040.00814.24
5.6.290.0060.01014.66
5.6.280.0060.04017.71
5.6.270.0070.00714.35
5.6.260.0090.00014.25
5.6.250.0030.01014.31
5.6.240.0030.01014.35
5.6.230.0030.01314.32
5.6.220.0050.02517.46
5.6.210.0100.04317.42
5.6.200.0080.04517.74
5.6.190.0080.02217.85
5.6.180.0020.05017.66
5.6.170.0050.02717.78
5.6.160.0050.04317.71
5.6.150.0080.03517.63
5.6.140.0080.03317.79
5.6.130.0050.04817.76
5.6.120.0030.03517.57
5.6.110.0110.04017.60
5.6.100.0080.04317.78
5.6.90.0050.02817.83
5.6.80.0080.03017.30
5.6.70.0100.04917.40
5.6.60.0020.04217.22
5.6.50.0060.04117.26
5.6.40.0030.02817.48
5.6.30.0050.04017.34
5.6.20.0080.03217.43
5.6.10.0080.03117.44
5.6.00.0060.05317.30
5.5.380.0060.00614.31
5.5.370.0030.00714.44
5.5.360.0070.04517.25
5.5.350.0050.04317.33
5.5.340.0030.03717.43
5.5.330.0090.02517.47
5.5.320.0110.03617.53
5.5.310.0060.04317.48
5.5.300.0090.04217.61
5.5.290.0020.02817.58
5.5.280.0030.05017.63
5.5.270.0020.04717.38
5.5.260.0080.03217.65
5.5.250.0090.04217.40
5.5.240.0030.02617.19
5.5.230.0090.03017.25
5.5.220.0080.04317.21
5.5.210.0060.04317.27
5.5.200.0060.04617.30
5.5.190.0100.03917.25
5.5.180.0030.04417.22
5.5.170.0030.00914.18
5.5.160.0070.02317.12
5.5.150.0150.03217.19
5.5.140.0020.04517.26
5.5.130.0060.04117.10
5.5.120.0080.03517.15
5.5.110.0030.03317.16
5.5.100.0080.04316.98
5.5.90.0070.04217.12
5.5.80.0070.04817.17
5.5.70.0000.04817.02
5.5.60.0070.04017.12
5.5.50.0140.03617.13
5.5.40.0080.05317.05
5.5.30.0080.04016.97
5.5.20.0050.03717.24
5.5.10.0070.03717.04
5.5.00.0080.04317.02
5.4.450.0080.03816.28
5.4.440.0040.04216.21
5.4.430.0050.02716.30
5.4.420.0060.03616.33
5.4.410.0050.03216.24
5.4.400.0030.04116.11
5.4.390.0010.02516.10
5.4.380.0070.04716.16
5.4.370.0100.04716.10
5.4.360.0070.03816.14
5.4.350.0100.03816.03
5.4.340.0020.04716.17
5.4.330.0040.00413.16
5.4.320.0100.03316.15
5.4.310.0070.04116.19
5.4.300.0050.04016.10
5.4.290.0050.03716.15
5.4.280.0050.03516.19
5.4.270.0020.03116.02
5.4.260.0000.02716.14
5.4.250.0030.04716.16
5.4.240.0020.04316.17
5.4.230.0060.04116.03
5.4.220.0070.03516.12
5.4.210.0080.03216.17
5.4.200.0160.02516.16
5.4.190.0070.03216.03
5.4.180.0020.03416.14
5.4.170.0050.04216.09
5.4.160.0100.03016.14
5.4.150.0120.02415.99
5.4.140.0080.02714.72
5.4.130.0050.03814.81
5.4.120.0050.04014.77
5.4.110.0050.02314.81
5.4.100.0030.04014.85
5.4.90.0090.03614.84
5.4.80.0040.03914.77
5.4.70.0030.02514.84
5.4.60.0020.03714.82
5.4.50.0100.03514.76
5.4.40.0030.04214.80
5.4.30.0050.02914.77
5.4.20.0030.02314.82
5.4.10.0030.04314.79
5.4.00.0060.04114.55
5.3.290.0000.03913.91
5.3.280.0100.03713.85
5.3.270.0060.03313.95
5.3.260.0070.03713.92
5.3.250.0050.04113.88
5.3.240.0050.02813.90
5.3.230.0050.02513.87
5.3.220.0040.04313.93
5.3.210.0020.04013.85
5.3.200.0030.03313.87
5.3.190.0020.03313.87
5.3.180.0080.02813.87
5.3.170.0050.04313.93
5.3.160.0050.02813.93
5.3.150.0060.03113.93
5.3.140.0060.04413.89
5.3.130.0030.02413.85
5.3.120.0060.03213.84
5.3.110.0070.04013.89
5.3.100.0070.04013.66
5.3.90.0090.03813.63
5.3.80.0030.04313.64
5.3.70.0030.03613.56
5.3.60.0020.03813.57
5.3.50.0070.04013.57
5.3.40.0070.03513.59
5.3.30.0100.03213.50
5.3.20.0050.03713.50
5.3.10.0030.03913.46
5.3.00.0020.04513.41
5.2.170.0070.04712.21
5.2.160.0030.06712.21
5.2.150.0070.06312.21
5.2.140.0070.05712.21
5.2.130.0000.04012.21
5.2.120.0070.05312.21
5.2.110.0100.06012.21
5.2.100.0030.06312.21
5.2.90.0030.05312.21
5.2.80.0000.06312.21
5.2.70.0000.06712.21
5.2.60.0000.06712.21
5.2.50.0130.04012.21
5.2.40.0070.05712.21
5.2.30.0000.06012.21
5.2.20.0070.06012.21
5.2.10.0000.06712.21
5.2.00.0100.05312.21
5.1.60.0070.05312.21
5.1.50.0000.05712.21
5.1.40.0070.05012.21
5.1.30.0000.05712.21
5.1.20.0000.05712.21
5.1.10.0000.05712.21
5.1.00.0070.05312.21
5.0.50.0000.04312.21
5.0.40.0030.04712.21
5.0.30.0000.03712.21
5.0.20.0030.04312.21
5.0.10.0030.02312.21
5.0.00.0000.06312.21
4.4.90.0000.03712.21
4.4.80.0030.03312.21
4.4.70.0030.02012.21
4.4.60.0100.02712.21
4.4.50.0000.03712.21
4.4.40.0000.04012.21
4.4.30.0070.03012.21
4.4.20.0030.03012.21
4.4.10.0000.02712.21
4.4.00.0000.05312.21
4.3.110.0030.02312.21
4.3.100.0030.02012.21
4.3.90.0000.02312.21
4.3.80.0030.03012.21
4.3.70.0000.01712.21
4.3.60.0000.02012.21
4.3.50.0070.01012.21
4.3.40.0030.02012.21
4.3.30.0030.01312.21
4.3.20.0070.01012.21
4.3.10.0000.02312.21
4.3.00.0000.01312.21

preferences:
40.03 ms | 400 KiB | 5 Q