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('adsad');

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.0210.00018.43
8.3.50.0140.00521.98
8.3.40.0070.00718.92
8.3.30.0170.00018.84
8.3.20.0080.00018.73
8.3.10.0040.00419.34
8.3.00.0080.00021.95
8.2.180.0000.01516.75
8.2.170.0150.00022.96
8.2.160.0130.00020.34
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00419.44
8.2.110.0030.00620.22
8.2.100.0090.00317.72
8.2.90.0000.00819.17
8.2.80.0000.00918.16
8.2.70.0030.00517.63
8.2.60.0040.00418.04
8.2.50.0080.00018.07
8.2.40.0040.00417.97
8.2.30.0040.00421.09
8.2.20.0030.00617.77
8.2.10.0040.00417.75
8.2.00.0040.00417.79
8.1.280.0120.00325.92
8.1.270.0000.00823.99
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0110.00023.84
8.1.230.0000.01120.78
8.1.220.0080.00018.77
8.1.210.0040.00418.78
8.1.200.0060.00317.35
8.1.190.0000.00817.52
8.1.180.0000.00818.10
8.1.170.0030.00618.64
8.1.160.0050.00218.97
8.1.150.0040.00418.73
8.1.140.0000.00817.54
8.1.130.0050.00317.81
8.1.120.0050.00217.39
8.1.110.0000.01117.51
8.1.100.0000.00717.52
8.1.90.0070.00017.48
8.1.80.0040.00417.42
8.1.70.0030.00317.52
8.1.60.0030.00617.65
8.1.50.0040.00417.52
8.1.40.0040.00417.57
8.1.30.0050.00317.59
8.1.20.0040.00417.63
8.1.10.0070.00017.61
8.1.00.0040.00417.57
8.0.300.0090.00319.64
8.0.290.0040.00417.18
8.0.280.0080.00018.50
8.0.270.0000.00917.18
8.0.260.0040.00416.86
8.0.250.0050.00317.03
8.0.240.0040.00417.08
8.0.230.0000.00817.07
8.0.220.0030.00516.99
8.0.210.0040.00416.99
8.0.200.0050.00217.13
8.0.190.0030.00416.98
8.0.180.0000.00716.90
8.0.170.0040.00416.86
8.0.160.0040.00417.01
8.0.150.0000.00717.04
8.0.140.0030.00516.86
8.0.130.0000.00713.52
8.0.120.0040.00416.88
8.0.110.0040.00416.86
8.0.100.0000.00717.01
8.0.90.0030.00516.96
8.0.80.0040.01216.95
8.0.70.0000.00717.05
8.0.60.0040.00416.90
8.0.50.0070.00016.99
8.0.30.0070.01417.17
8.0.20.0110.02217.40
8.0.10.0050.00216.94
8.0.00.0130.00716.78
7.4.330.0030.00314.73
7.4.320.0030.00316.69
7.4.300.0000.00616.50
7.4.290.0070.00016.47
7.4.280.0070.00016.56
7.4.270.0030.00316.54
7.4.260.0030.00313.28
7.4.250.0030.00516.62
7.4.240.0040.00416.67
7.4.230.0000.00716.74
7.4.220.0180.00016.45
7.4.210.0050.01016.64
7.4.200.0040.00416.70
7.4.190.0030.00316.50
7.4.160.0110.00616.54
7.4.150.0030.01417.40
7.4.140.0150.00517.86
7.4.130.0130.00716.58
7.4.120.0110.00716.54
7.4.110.0120.00616.70
7.4.100.0070.01416.59
7.4.90.0040.01516.71
7.4.80.0030.01419.37
7.4.70.0160.00716.62
7.4.60.0060.01216.75
7.4.50.0040.00416.61
7.4.40.0070.01122.52
7.4.30.0060.01016.75
7.4.10.0060.01214.98
7.4.00.0020.01515.10
7.3.330.0030.00313.35
7.3.320.0030.00313.36
7.3.310.0000.00716.27
7.3.300.0030.00316.24
7.3.290.0060.00916.40
7.3.280.0100.00416.39
7.3.270.0080.01117.40
7.3.260.0130.01018.24
7.3.250.0080.01016.40
7.3.240.0110.00716.58
7.3.230.0080.00816.45
7.3.210.0030.01316.37
7.3.200.0210.00419.39
7.3.190.0060.01016.43
7.3.180.0130.00316.65
7.3.170.0100.00716.54
7.3.160.0070.00716.61
7.3.130.0060.01214.62
7.3.120.0020.01414.73
7.3.110.0070.01014.96
7.3.100.0090.00315.09
7.3.90.0120.00314.74
7.3.80.0040.00714.77
7.3.70.0070.01014.85
7.3.60.0030.01314.86
7.3.50.0000.01514.66
7.3.40.0060.00914.85
7.3.30.0050.00514.89
7.3.20.0060.00916.73
7.3.10.0120.00016.57
7.3.00.0130.00316.69
7.2.330.0100.01016.74
7.2.320.0070.01016.86
7.2.310.0120.01216.40
7.2.300.0040.01116.82
7.2.290.0030.01516.54
7.2.260.0130.00614.89
7.2.250.0000.01714.91
7.2.240.0060.01215.17
7.2.230.0060.00915.02
7.2.220.0090.00615.02
7.2.210.0100.00715.30
7.2.200.0100.00315.04
7.2.190.0030.00615.09
7.2.180.0070.00714.88
7.2.170.0070.01015.18
7.2.160.0070.00715.00
7.2.150.0040.01117.09
7.2.140.0070.01016.96
7.2.130.0110.00716.86
7.2.120.0140.00016.72
7.2.110.0100.00316.88
7.2.100.0080.00817.09
7.2.90.0060.01016.84
7.2.80.0060.01316.72
7.2.70.0030.00917.13
7.2.60.0110.00516.79
7.2.50.0030.00916.64
7.2.40.0090.00316.80
7.2.30.0030.00916.86
7.2.20.0080.00417.12
7.2.10.0000.01316.97
7.2.00.0030.00918.26
7.1.330.0070.01015.47
7.1.320.0100.00015.80
7.1.310.0080.00415.46
7.1.300.0040.00715.79
7.1.290.0030.00715.60
7.1.280.0120.00315.53
7.1.270.0060.00915.68
7.1.260.0060.00615.78
7.1.250.0030.00715.77
7.1.240.0040.00815.79
7.1.230.0060.00615.76
7.1.220.0030.01015.48
7.1.210.0090.00315.81
7.1.200.0100.00615.50
7.1.190.0000.01215.64
7.1.180.0060.01015.70
7.1.170.0090.00615.63
7.1.160.0080.00415.45
7.1.150.0030.00615.47
7.1.140.0060.00615.69
7.1.130.0100.00315.68
7.1.120.0060.00915.71
7.1.110.0000.01515.82
7.1.100.0070.00417.03
7.1.90.0040.01115.88
7.1.80.0090.00615.57
7.1.70.0020.00816.33
7.1.60.0090.00817.51
7.1.50.0090.01116.27
7.1.40.0000.01416.01
7.1.30.0000.01215.77
7.1.20.0060.00915.79
7.1.10.0070.00715.61
7.1.00.0060.04119.05
7.0.330.0030.00915.34
7.0.320.0090.00615.43
7.0.310.0030.01015.39
7.0.300.0000.01315.43
7.0.290.0060.00315.34
7.0.280.0070.00715.33
7.0.270.0000.00815.36
7.0.260.0040.01115.46
7.0.250.0070.00715.38
7.0.240.0080.00815.57
7.0.230.0030.00915.12
7.0.220.0030.01115.40
7.0.210.0030.01015.46
7.0.200.0050.00416.17
7.0.190.0000.01015.49
7.0.180.0030.01015.30
7.0.170.0030.00515.54
7.0.160.0000.01315.45
7.0.150.0070.00715.26
7.0.140.0030.04218.66
7.0.130.0030.00515.62
7.0.120.0040.01115.30
7.0.110.0080.01115.37
7.0.100.0050.04617.71
7.0.90.0070.02417.78
7.0.80.0130.02317.65
7.0.70.0150.02217.66
7.0.60.0030.04917.64
7.0.50.0180.04317.95
7.0.40.0070.04516.79
7.0.30.0050.04916.72
7.0.20.0040.04416.70
7.0.10.0080.02216.86
7.0.00.0090.02816.77
5.6.400.0070.01014.34
5.6.390.0030.01214.37
5.6.380.0040.00414.33
5.6.370.0070.00714.35
5.6.360.0030.00614.34
5.6.350.0070.00414.10
5.6.340.0040.00714.21
5.6.330.0040.00714.43
5.6.320.0030.00914.20
5.6.310.0110.00414.54
5.6.300.0030.00914.54
5.6.290.0030.00913.92
5.6.280.0090.03817.71
5.6.270.0000.01414.31
5.6.260.0100.00614.35
5.6.250.0060.02617.64
5.6.240.0080.02017.68
5.6.230.0070.02717.52
5.6.220.0100.03717.46
5.6.210.0090.03117.43
5.6.200.0110.01817.66
5.6.190.0080.03717.77
5.6.180.0050.04917.64
5.6.170.0110.04317.72
5.6.160.0030.04517.78
5.6.150.0110.04717.62
5.6.140.0100.05217.61
5.6.130.0070.04417.62
5.6.120.0070.04717.85
5.6.110.0050.04717.64
5.6.100.0050.04417.66
5.6.90.0080.04017.69
5.6.80.0050.04417.34
5.6.70.0080.03617.33
5.6.60.0120.02817.29
5.6.50.0080.03017.36
5.6.40.0060.03817.40
5.6.30.0050.02617.32
5.6.20.0050.04317.39
5.6.10.0080.02517.24
5.6.00.0140.03717.29
5.5.380.0070.04017.32
5.5.370.0080.04217.43
5.5.360.0100.04517.40
5.5.350.0080.04217.37
5.5.340.0130.03817.62
5.5.330.0080.04117.51
5.5.320.0040.04317.73
5.5.310.0050.04617.63
5.5.300.0090.04017.40
5.5.290.0030.04017.59
5.5.280.0100.03717.74
5.5.270.0050.04517.64
5.5.260.0050.02917.45
5.5.250.0060.02817.28
5.5.240.0050.03317.16
5.5.230.0160.03717.29
5.5.220.0140.03917.26
5.5.210.0130.03817.22
5.5.200.0120.03817.25
5.5.190.0080.03317.25
5.5.180.0130.03117.15
5.5.170.0090.00014.33
5.5.160.0050.03816.92
5.5.150.0090.03317.24
5.5.140.0090.04217.18
5.5.130.0060.03817.20
5.5.120.0070.04517.14
5.5.110.0080.03817.15
5.5.100.0150.03317.09
5.5.90.0090.03216.90
5.5.80.0110.04017.11
5.5.70.0090.04117.09
5.5.60.0030.02617.02
5.5.50.0120.02817.24
5.5.40.0050.03917.23
5.5.30.0080.03117.06
5.5.20.0050.03417.13
5.5.10.0080.04017.10
5.5.00.0010.03617.03
5.4.450.0060.02615.19
5.4.440.0050.04815.32
5.4.430.0030.04215.20
5.4.420.0070.03515.06
5.4.410.0060.03215.20
5.4.400.0080.02814.96
5.4.390.0070.03215.00
5.4.380.0050.03615.08
5.4.370.0070.04115.13
5.4.360.0080.03815.05
5.4.350.0040.03015.10
5.4.340.0050.02514.92
5.4.330.0000.00910.68
5.4.320.0050.04215.18
5.4.310.0050.02514.87
5.4.300.0050.03714.91
5.4.290.0030.04315.19
5.4.280.0060.03215.09
5.4.270.0070.03715.02
5.4.260.0070.04214.94
5.4.250.0100.03515.09
5.4.240.0050.03815.06
5.4.230.0040.03714.88
5.4.220.0030.03215.06
5.4.210.0050.02314.86
5.4.200.0100.02814.98
5.4.190.0030.04014.89
5.4.180.0030.04514.98
5.4.170.0030.04714.93
5.4.160.0050.04214.97
5.4.150.0030.02814.80
5.4.140.0060.04113.89
5.4.130.0070.04413.72
5.4.120.0070.03513.85
5.4.110.0020.02313.84
5.4.100.0070.03313.64
5.4.90.0030.04013.75
5.4.80.0070.02813.79
5.4.70.0050.03513.79
5.4.60.0070.02513.82
5.4.50.0050.04113.74
5.4.40.0070.01913.65
5.4.30.0060.03813.56
5.4.20.0040.04113.65
5.4.10.0050.03013.75
5.4.00.0030.03913.45
5.3.290.0050.04112.76
5.3.280.0060.03912.50
5.3.270.0080.04212.68
5.3.260.0050.04212.68
5.3.250.0030.04112.44
5.3.240.0090.03212.50
5.3.230.0040.02612.59
5.3.220.0080.03412.46
5.3.210.0030.02812.54
5.3.200.0060.04112.37
5.3.190.0060.04112.66
5.3.180.0080.01812.55
5.3.170.0050.04212.64
5.3.160.0050.03612.71
5.3.150.0070.04012.47
5.3.140.0060.04012.57
5.3.130.0030.04112.62
5.3.120.0030.01812.44
5.3.110.0010.03312.46
5.3.100.0070.01912.31
5.3.90.0030.02212.29
5.3.80.0020.04212.35
5.3.70.0030.03012.32
5.3.60.0080.02512.29
5.3.50.0070.04012.22
5.3.40.0070.03712.27
5.3.30.0020.02312.31
5.3.20.0000.03212.13
5.3.10.0060.02112.11
5.3.00.0050.02712.00
5.2.170.0000.07011.09
5.2.160.0030.05710.98
5.2.150.0070.05011.14
5.2.140.0070.05311.09
5.2.130.0070.03711.12
5.2.120.0030.05011.09
5.2.110.0070.04711.09
5.2.100.0070.04011.02
5.2.90.0130.05311.09
5.2.80.0070.06310.93
5.2.70.0030.06011.07
5.2.60.0070.06011.05
5.2.50.0070.02711.05
5.2.40.0030.04311.03
5.2.30.0000.05710.76
5.2.20.0100.05710.77
5.2.10.0030.06310.92
5.2.00.0070.02710.63
5.1.60.0000.0279.98
5.1.50.0100.01710.03
5.1.40.0070.0509.81
5.1.30.0070.02310.36
5.1.20.0000.04310.41
5.1.10.0030.05310.07
5.1.00.0100.05010.11
5.0.50.0000.0278.57
5.0.40.0070.0408.45
5.0.30.0000.0508.25
5.0.20.0070.0408.30
5.0.10.0070.0478.25
5.0.00.0030.0478.24
4.4.90.0100.0107.69
4.4.80.0070.0277.69
4.4.70.0000.0307.69
4.4.60.0070.0177.69
4.4.50.0070.0277.69
4.4.40.0000.0377.69
4.4.30.0000.0207.69
4.4.20.0070.0337.69
4.4.10.0100.0237.69
4.4.00.0030.0337.69
4.3.110.0030.0137.69
4.3.100.0070.0337.69
4.3.90.0030.0177.69
4.3.80.0000.0577.69
4.3.70.0070.0377.69
4.3.60.0070.0337.69
4.3.50.0030.0177.69
4.3.40.0130.0377.69
4.3.30.0030.0207.69
4.3.20.0030.0277.69
4.3.10.0000.0207.69
4.3.00.0030.0307.69

preferences:
54.05 ms | 401 KiB | 5 Q