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.'); } $numeralString = ''; while (0 < $number) { foreach ($this->_integerNumeralMap 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(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.0110.00416.75
8.3.50.0120.00517.51
8.3.40.0000.01518.73
8.3.30.0110.00418.49
8.3.20.0070.00718.60
8.3.10.0040.00420.36
8.3.00.0060.00319.24
8.2.180.0140.00718.29
8.2.170.0070.01022.96
8.2.160.0090.00621.06
8.2.150.0000.00824.18
8.2.140.0060.00324.66
8.2.130.0070.00726.16
8.2.120.0080.00020.88
8.2.110.0030.00620.95
8.2.100.0080.00417.78
8.2.90.0080.00019.38
8.2.80.0050.00519.21
8.2.70.0030.00517.63
8.2.60.0040.00417.93
8.2.50.0090.00018.07
8.2.40.0040.00418.16
8.2.30.0000.00718.03
8.2.20.0050.00317.66
8.2.10.0040.00417.79
8.2.00.0060.00317.83
8.1.280.0110.00425.92
8.1.270.0130.00624.66
8.1.260.0040.00426.35
8.1.250.0110.00728.09
8.1.240.0030.00622.58
8.1.230.0060.00620.85
8.1.220.0000.00817.74
8.1.210.0030.00618.93
8.1.200.0030.00617.35
8.1.190.0040.00417.41
8.1.180.0000.00918.10
8.1.170.0000.00918.91
8.1.160.0070.00018.94
8.1.150.0040.00418.57
8.1.140.0040.00417.48
8.1.130.0000.00717.76
8.1.120.0030.00517.51
8.1.110.0000.00717.38
8.1.100.0000.00717.48
8.1.90.0040.00417.47
8.1.80.0070.00017.48
8.1.70.0040.00417.38
8.1.60.0060.00317.62
8.1.50.0040.00417.50
8.1.40.0080.00017.57
8.1.30.0000.00817.59
8.1.20.0040.00417.69
8.1.10.0030.00517.67
8.1.00.0040.00417.40
8.0.300.0000.00820.02
8.0.290.0040.00416.60
8.0.280.0050.00318.48
8.0.270.0030.00317.30
8.0.260.0000.00716.73
8.0.250.0000.01116.88
8.0.240.0050.00217.03
8.0.230.0000.00716.96
8.0.220.0000.00716.83
8.0.210.0030.00316.96
8.0.200.0070.00016.99
8.0.190.0030.00516.95
8.0.180.0000.00716.85
8.0.170.0040.00416.90
8.0.160.0050.00216.87
8.0.150.0000.00816.84
8.0.140.0000.01016.85
8.0.130.0000.00613.37
8.0.120.0030.00516.79
8.0.110.0080.00016.88
8.0.100.0000.00716.81
8.0.90.0080.00016.80
8.0.80.0120.00316.87
8.0.70.0040.00416.87
8.0.60.0000.00816.86
8.0.50.0040.00416.81
8.0.30.0070.01316.93
8.0.20.0110.00817.16
8.0.10.0040.00417.01
8.0.00.0090.01216.84
7.4.330.0000.00513.09
7.4.320.0000.00616.64
7.4.300.0000.00616.54
7.4.290.0030.00316.61
7.4.280.0000.00816.67
7.4.270.0070.00016.61
7.4.260.0050.00013.20
7.4.250.0050.00316.52
7.4.240.0030.00616.52
7.4.230.0030.00316.72
7.4.220.0140.00716.64
7.4.210.0080.00716.65
7.4.200.0040.00416.65
7.4.190.0030.00316.67
7.4.160.0100.01316.54
7.4.150.0100.00716.59
7.4.140.0120.00516.67
7.4.130.0110.01116.60
7.4.120.0120.00816.48
7.4.110.0100.00716.45
7.4.100.0060.01216.46
7.4.90.0110.00616.48
7.4.80.0060.01119.39
7.4.70.0060.01016.63
7.4.60.0160.00616.49
7.4.50.0040.00716.61
7.4.40.0060.01016.45
7.4.30.0130.00316.51
7.4.10.0110.00714.85
7.4.00.0040.00914.88
7.3.330.0000.00613.22
7.3.320.0030.00313.38
7.3.310.0020.00516.41
7.3.300.0030.00316.36
7.3.290.0100.01016.38
7.3.280.0080.00616.37
7.3.270.0060.01016.38
7.3.260.0070.01016.67
7.3.250.0090.00916.47
7.3.240.0060.01016.45
7.3.230.0100.00716.63
7.3.210.0120.00416.55
7.3.200.0130.00316.53
7.3.190.0090.00916.37
7.3.180.0060.00916.61
7.3.170.0110.01116.36
7.3.160.0090.00816.37
7.3.130.0030.01214.92
7.3.120.0080.00814.79
7.3.110.0150.00314.91
7.3.100.0120.00314.99
7.3.90.0120.00314.82
7.3.80.0060.00614.86
7.3.70.0000.01414.98
7.3.60.0100.00314.80
7.3.50.0070.00314.93
7.3.40.0030.00914.88
7.3.30.0030.00714.84
7.3.20.0040.01216.32
7.3.10.0080.00616.62
7.3.00.0050.00516.65
7.2.330.0110.00616.70
7.2.320.0150.00316.55
7.2.310.0100.01316.86
7.2.300.0040.01216.78
7.2.290.0000.01616.84
7.2.260.0040.01115.31
7.2.250.0130.00714.73
7.2.240.0030.01314.82
7.2.230.0000.01515.15
7.2.220.0040.01515.10
7.2.210.0080.00814.95
7.2.200.0080.00415.08
7.2.190.0030.01015.08
7.2.180.0060.00315.04
7.2.170.0030.00515.15
7.2.160.0070.00315.12
7.2.150.0060.00916.79
7.2.140.0000.01516.85
7.2.130.0120.00316.94
7.2.120.0030.01016.76
7.2.110.0120.00316.75
7.2.100.0040.00716.89
7.2.90.0090.00916.84
7.2.80.0060.00817.04
7.2.70.0070.00717.11
7.2.60.0050.00617.09
7.2.50.0090.00316.84
7.2.40.0070.00516.97
7.2.30.0060.00316.74
7.2.20.0060.00816.98
7.2.10.0050.01316.84
7.2.00.0020.01117.63
7.1.330.0070.00716.08
7.1.320.0070.01015.86
7.1.310.0000.01015.64
7.1.300.0030.00516.05
7.1.290.0040.00415.84
7.1.280.0130.00015.82
7.1.270.0100.00715.64
7.1.260.0080.00315.90
7.1.250.0040.00915.56
7.1.240.0090.00615.87
7.1.230.0120.00315.88
7.1.220.0030.01115.60
7.1.210.0000.01515.86
7.1.200.0000.01715.90
7.1.190.0060.00615.94
7.1.180.0100.00315.96
7.1.170.0060.00315.96
7.1.160.0110.00015.76
7.1.150.0030.00715.68
7.1.140.0130.00715.77
7.1.130.0030.00615.84
7.1.120.0080.00315.76
7.1.110.0030.01015.61
7.1.100.0050.01117.05
7.1.90.0150.00015.49
7.1.80.0080.00015.63
7.1.70.0060.00516.47
7.1.60.0070.01017.61
7.1.50.0030.00716.36
7.1.40.0030.01215.68
7.1.30.0040.01215.80
7.1.20.0070.00315.88
7.1.10.0080.00615.84
7.1.00.0050.03519.16
7.0.330.0040.00715.61
7.0.320.0000.01115.36
7.0.310.0040.00815.43
7.0.300.0030.01215.55
7.0.290.0030.01015.43
7.0.280.0090.00615.44
7.0.270.0000.00815.33
7.0.260.0040.01115.33
7.0.250.0060.00615.41
7.0.240.0000.01315.41
7.0.230.0110.00415.65
7.0.220.0050.00515.59
7.0.210.0040.01115.55
7.0.200.0020.01115.94
7.0.190.0030.01415.32
7.0.180.0070.00715.52
7.0.170.0030.00915.44
7.0.160.0030.00615.33
7.0.150.0070.00715.58
7.0.140.0060.03518.77
7.0.130.0040.01115.54
7.0.120.0080.02118.71
7.0.110.0030.02318.71
7.0.100.0000.02818.72
7.0.90.0030.02818.70
7.0.80.0060.04018.81
7.0.70.0030.04318.85
7.0.60.0020.02918.69
7.0.50.0020.02418.69
7.0.40.0010.03116.78
7.0.30.0070.02516.76
7.0.20.0050.02816.86
7.0.10.0050.02216.71
7.0.00.0070.02216.77
5.6.400.0070.00314.58
5.6.390.0040.01114.64
5.6.380.0040.01114.18
5.6.370.0070.00714.43
5.6.360.0060.01014.59
5.6.350.0030.01014.27
5.6.340.0030.01414.74
5.6.330.0040.00714.71
5.6.320.0070.00714.39
5.6.310.0030.01014.16
5.6.300.0030.00714.74
5.6.290.0070.00714.36
5.6.280.0070.03817.64
5.6.270.0030.02317.87
5.6.260.0020.02617.81
5.6.250.0070.04517.62
5.6.240.0050.02517.68
5.6.230.0030.04217.53
5.6.220.0060.02817.76
5.6.210.0030.03317.65
5.6.200.0020.02617.60
5.6.190.0010.02617.49
5.6.180.0030.02217.55
5.6.170.0070.01817.69
5.6.160.0050.02217.60
5.6.150.0060.02517.75
5.6.140.0030.02417.82
5.6.130.0070.02017.63
5.6.120.0020.02717.66
5.6.110.0060.03517.56
5.6.100.0050.02217.66
5.6.90.0040.02017.73
5.6.80.0060.03317.37
5.6.70.0000.02617.36
5.6.60.0060.02317.24
5.6.50.0060.03517.30
5.6.40.0070.02817.30
5.6.30.0030.02517.31
5.6.20.0090.02017.34
5.6.10.0020.02117.17
5.6.00.0030.02217.44
5.5.380.0030.03915.90
5.5.370.0060.03616.04
5.5.360.0070.03716.12
5.5.350.0090.03715.88
5.5.340.0000.03316.32
5.5.330.0040.02916.26
5.5.320.0050.02116.45
5.5.310.0020.04016.24
5.5.300.0050.02316.12
5.5.290.0000.02116.23
5.5.280.0020.02416.33
5.5.270.0010.02816.29
5.5.260.0030.04016.10
5.5.250.0020.02316.05
5.5.240.0000.02815.96
5.5.230.0070.02215.74
5.5.220.0030.02315.68
5.5.210.0020.02415.98
5.5.200.0030.02515.73
5.5.190.0060.02015.87
5.5.180.0020.02515.72
5.5.170.0030.01114.29
5.5.160.0020.04015.83
5.5.150.0050.04115.81
5.5.140.0060.03015.97
5.5.130.0080.04015.78
5.5.120.0080.04315.79
5.5.110.0030.03015.85
5.5.100.0030.04215.77
5.5.90.0040.02415.60
5.5.80.0070.02315.84
5.5.70.0030.03515.93
5.5.60.0020.04415.68
5.5.50.0030.03815.80
5.5.40.0060.02515.76
5.5.30.0020.03715.78
5.5.20.0070.03715.50
5.5.10.0020.02415.76
5.5.00.0050.03415.71
5.4.450.0020.02116.33
5.4.440.0060.02116.35
5.4.430.0000.03116.38
5.4.420.0040.02216.30
5.4.410.0020.02616.37
5.4.400.0040.02016.23
5.4.390.0040.02316.30
5.4.380.0080.01516.22
5.4.370.0050.01816.15
5.4.360.0060.02016.27
5.4.350.0020.02216.15
5.4.340.0030.03916.24
5.4.330.0000.01113.35
5.4.320.0040.02716.10
5.4.310.0070.03516.16
5.4.300.0080.03916.26
5.4.290.0050.03216.14
5.4.280.0020.04116.24
5.4.270.0040.04216.15
5.4.260.0050.03716.26
5.4.250.0070.03916.16
5.4.240.0040.03116.27
5.4.230.0020.04116.23
5.4.220.0070.03316.26
5.4.210.0000.02316.16
5.4.200.0030.02316.22
5.4.190.0070.03516.15
5.4.180.0070.02316.14
5.4.170.0040.03616.26
5.4.160.0020.04416.21
5.4.150.0100.03516.11
5.4.140.0040.02514.84
5.4.130.0020.02014.83
5.4.120.0000.02914.97
5.4.110.0050.03014.92
5.4.100.0050.02314.96
5.4.90.0030.02914.88
5.4.80.0070.02414.87
5.4.70.0020.04015.00
5.4.60.0070.03214.93
5.4.50.0020.04614.86
5.4.40.0010.02414.94
5.4.30.0050.02214.91
5.4.20.0040.01914.91
5.4.10.0030.04114.92
5.4.00.0030.03514.62
5.3.290.0040.02414.02
5.3.280.0020.02513.98
5.3.270.0020.03314.05
5.3.260.0070.02514.03
5.3.250.0030.03613.99
5.3.240.0000.02813.96
5.3.230.0020.04513.98
5.3.220.0010.02414.03
5.3.210.0070.03713.98
5.3.200.0050.03214.03
5.3.190.0030.03813.96
5.3.180.0030.03013.96
5.3.170.0050.02313.95
5.3.160.0050.03213.94
5.3.150.0030.03513.95
5.3.140.0030.03514.02
5.3.130.0000.03913.96
5.3.120.0030.02313.93
5.3.110.0050.04013.95
5.3.100.0020.04113.72
5.3.90.0020.03013.76
5.3.80.0020.03213.76
5.3.70.0020.02813.67
5.3.60.0020.02913.70
5.3.50.0040.02013.77
5.3.40.0000.02613.65
5.3.30.0010.02713.63
5.3.20.0070.03013.52
5.3.10.0040.03813.51
5.3.00.0020.02813.49
5.2.170.0030.06311.05
5.2.160.0030.06011.08
5.2.150.0030.02711.10
5.2.140.0000.03011.08
5.2.130.0030.03011.14
5.2.120.0030.03311.18
5.2.110.0000.04711.05
5.2.100.0000.03011.02
5.2.90.0030.02711.26
5.2.80.0000.04711.11
5.2.70.0000.02710.99
5.2.60.0000.04010.99
5.2.50.0000.03711.04
5.2.40.0000.04310.89
5.2.30.0000.02710.92
5.2.20.0030.05310.90
5.2.10.0000.02710.77
5.2.00.0000.03010.68
5.1.60.0000.0239.94
5.1.50.0000.04310.25
5.1.40.0030.02310.05
5.1.30.0070.04010.33
5.1.20.0000.02310.36
5.1.10.0030.04310.32
5.1.00.0030.04710.24
5.0.50.0000.0209.72
5.0.40.0030.0279.72
5.0.30.0000.0539.72
5.0.20.0070.0379.72
5.0.10.0000.0309.72
5.0.00.0030.0439.72
4.4.90.0030.0209.72
4.4.80.0000.0139.72
4.4.70.0000.0339.72
4.4.60.0030.0239.72
4.4.50.0030.0139.72
4.4.40.0070.0239.72
4.4.30.0000.0179.72
4.4.20.0000.0309.72
4.4.10.0000.0379.72
4.4.00.0000.0479.72
4.3.110.0030.0309.72
4.3.100.0000.0139.72
4.3.90.0000.0209.72
4.3.80.0000.0209.72
4.3.70.0030.0279.72
4.3.60.0000.0279.72
4.3.50.0000.0239.72
4.3.40.0000.0279.72
4.3.30.0000.0339.72
4.3.20.0000.0339.72
4.3.10.0000.0179.72
4.3.00.0000.0179.72

preferences:
52.64 ms | 401 KiB | 5 Q