3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * A code sample which converts odd integers to word strings and returns the sum of the common factors of even numbers. * * The input is assumed to be a random list of integers. For the sum of the common factors of even numbers * only positive values are taken into consideration */ error_reporting(E_ALL); function exception_handler($exception) { echo get_class($exception). ' : ' . $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); //start $iB = new IntelligentBee(array(6,12,48, 7, 101, 67)); //$iB->processOddNumbers(); //$sum = $iB->processEvenNumbers(); //echo PHP_EOL.'Sum of common factors: ' . $sum . PHP_EOL; $a = $iB->getCmmdcSum(); echo PHP_EOL.' Sum is ' . $a[1]. PHP_EOL; //end class IntelligentBee{ const OneHundred = 100; const OneThousand = 1000; const OneMillion = 1000000; const OneBillion = 1000000000; protected $minCommonFactors = []; protected $oddNumbers = []; protected $evenNumbers = []; protected $startInt; protected $endInt; public function __construct(array $arrayOfIntegers){ $startInt = min($arrayOfIntegers); $endInt = max($arrayOfIntegers); if(abs($startInt) > self::OneBillion || abs($startInt) > self::OneBillion){ throw new OutOfRangeException(sprintf("We can only process numbers between %s and %s! %s provided!", self::OneBillion, self::OneBillion, $startInt)); } if(abs($endInt) > self::OneBillion || abs($endInt) > self::OneBillion){ throw new OutOfRangeException(sprintf("We can only process numbers between %s and %s! %s provided!", self::OneBillion, self::OneBillion, $startInt)); } $this->startInt = $startInt; $this->endInt = $endInt; $arrayOfIntegers = range(2, self::OneMillion); //split it into 2 arrays, one for odd numbers and one for even numbers to make it easier to perform each task $this->splitNumbers($arrayOfIntegers); } public function getCmmdcSum() { $values = $this->evenNumbers; $num_values = count($values); $x = current($values); $y = next($values); for ($i = 1; $i < $num_values; $i ++) { $a = max($x, $y); $b = min($x, $y); $c= 1; do { $c = $a % $b; $gcf = $b; $a = $b; $b = $c; } while ($c != 0); $x = $gcf; $y = next($values); } $sum = 0; for($i = 1; $i <= $gcf; $i ++){ if(0 === $gcf % $i){ $sum += $i; } } return array($gcf, $sum); } }

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.0250.00431.88
8.3.50.0140.01233.09
8.3.40.0220.00734.09
8.3.30.0180.01134.46
8.3.20.0240.01035.41
8.3.10.0030.01038.95
8.3.00.0100.00734.23
8.2.180.0290.01331.50
8.2.170.0250.00334.34
8.2.160.0280.00035.59
8.2.150.0120.00434.24
8.2.140.0060.00636.02
8.2.130.0050.00538.41
8.2.120.0100.00036.70
8.2.110.0130.00037.61
8.2.100.0190.00933.28
8.2.90.0030.01234.53
8.2.80.0060.01032.86
8.2.70.0100.00632.75
8.2.60.0130.00333.05
8.2.50.0090.00632.75
8.2.40.0150.00435.13
8.2.30.0100.00633.28
8.2.20.0110.00432.90
8.2.10.0070.00733.28
8.2.00.0100.00732.91
8.1.280.0520.01946.48
8.1.270.0030.00623.97
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0000.01123.80
8.1.230.0090.00319.09
8.1.220.0080.00017.74
8.1.210.0090.00018.77
8.1.200.0060.00317.35
8.1.190.0060.00317.13
8.1.180.0040.00718.10
8.1.170.0040.00418.64
8.1.160.0040.00422.09
8.1.150.0000.01018.57
8.1.140.0080.00017.48
8.1.130.0000.00717.72
8.1.120.0000.00717.45
8.1.110.0040.00417.54
8.1.100.0040.00417.38
8.1.90.0000.00717.55
8.1.80.0040.00417.53
8.1.70.0070.00017.44
8.1.60.0000.00917.50
8.1.50.0040.00417.56
8.1.40.0000.00817.50
8.1.30.0040.00417.63
8.1.20.0040.00417.57
8.1.10.0130.01047.90
8.1.00.0150.00747.84
8.0.300.0150.00647.66
8.0.290.0150.00647.78
8.0.280.0150.00648.68
8.0.270.0260.00047.63
8.0.260.0160.00347.57
8.0.250.0110.00747.28
8.0.240.0090.01247.23
8.0.230.0140.00747.33
8.0.220.0110.01147.21
8.0.210.0090.01247.22
8.0.200.0180.00047.23
8.0.190.0090.01247.29
8.0.180.0120.00947.32
8.0.170.0100.01047.16
8.0.160.0130.00747.25
8.0.150.0170.00747.21
8.0.140.0140.01447.21
8.0.130.0100.01043.72
8.0.120.0130.01047.22
8.0.110.0150.00747.06
8.0.100.0130.00747.04
8.0.90.0100.01047.16
8.0.80.0250.01947.20
8.0.70.0120.00947.11
8.0.60.0140.00647.16
8.0.50.0220.00347.12
8.0.30.0360.01847.52
8.0.20.0340.02047.41
8.0.10.0130.01047.41
8.0.00.0420.01346.99
7.4.330.0140.01045.47
7.4.320.0070.01346.84
7.4.300.0190.00646.92
7.4.290.0130.01046.82
7.4.280.0230.00346.72
7.4.270.0150.00746.86
7.4.260.0220.00346.90
7.4.250.0130.01046.74
7.4.240.0130.00846.83
7.4.230.0180.00346.67
7.4.220.0490.02346.96
7.4.210.0290.01646.90
7.4.200.0130.01046.90
7.4.190.0100.01046.78
7.4.160.0400.00946.83
7.4.150.0450.02846.59
7.4.140.0430.01846.89
7.4.130.0440.01746.97
7.4.120.0380.01346.91
7.4.110.0300.02346.91
7.4.100.0320.01946.68
7.4.90.0310.02046.96
7.4.80.0270.02646.98
7.4.70.0210.03146.96
7.4.60.0390.01346.95
7.4.50.0160.01046.72
7.4.40.0390.01446.87
7.4.30.0310.01747.04
7.4.00.0130.01945.30
7.3.330.0190.00443.71
7.3.320.0200.00443.46
7.3.310.0140.01046.67
7.3.300.0190.00046.62
7.3.290.0350.01446.60
7.3.280.0320.02346.68
7.3.270.0410.01146.64
7.3.260.0260.03046.63
7.3.250.0430.01846.87
7.3.240.0330.02046.56
7.3.230.0280.02546.84
7.3.210.0280.02446.63
7.3.200.0390.01346.67
7.3.190.0360.02646.73
7.3.180.0390.01346.88
7.3.170.0350.01646.67
7.3.160.0310.02146.71
7.3.120.0300.00745.13
7.2.330.0360.01847.02
7.2.320.0410.01547.12
7.2.310.0410.02147.09
7.2.300.0290.02247.05
7.2.290.0320.02347.17
7.2.120.0070.01748.73
7.2.110.0100.01048.63
7.2.100.0130.01348.43
7.2.90.0130.01648.44
7.2.80.0150.01548.41
7.2.70.0190.01348.85
7.2.60.0370.01048.79
7.2.50.0150.01848.97
7.2.40.0160.01648.70
7.2.30.0230.00648.96
7.2.20.0110.02348.91
7.2.10.0210.00948.91
7.2.00.0140.01250.04
7.1.240.0070.02247.52
7.1.230.0160.00947.75
7.1.220.0140.01447.49
7.1.210.0180.01247.78
7.1.200.0210.01047.72
7.1.190.0080.02347.80
7.1.180.0220.01147.77
7.1.170.0040.02347.66
7.1.160.0110.02347.61
7.1.150.0140.01447.80
7.1.140.0080.01647.74
7.1.130.0170.01147.59
7.1.120.0170.00947.70
7.1.110.0120.01247.94
7.1.100.0090.01548.80
7.1.90.0240.01047.53
7.1.80.0150.01147.82
7.1.70.0600.01248.39
7.1.60.0360.02148.53
7.1.50.0290.01548.22
7.1.40.0060.02647.70
7.1.30.0130.01647.80
7.1.20.0630.02047.85
7.1.10.0100.01747.88
7.1.00.0120.04850.85
7.0.320.0160.01247.23
7.0.310.0150.01247.54
7.0.300.0030.02747.09
7.0.290.0140.01447.43
7.0.280.0080.02447.44
7.0.270.0210.00347.09
7.0.260.0110.01847.61
7.0.250.0130.02147.48
7.0.240.0000.02447.54
7.0.230.0190.01347.24
7.0.220.0150.01547.48
7.0.210.0230.01347.42
7.0.200.1080.01447.15
7.0.190.0170.01047.58
7.0.180.0170.01447.50
7.0.170.0180.00947.31
7.0.160.0110.01547.54
7.0.150.0160.01647.18
7.0.140.0180.04150.71
7.0.130.0210.00847.39
7.0.120.0090.01747.65
7.0.110.0640.01247.57
7.0.100.0160.00847.43
7.0.90.0140.01447.55
7.0.80.0100.01747.53
7.0.70.0170.01047.37
7.0.60.0110.04648.86
7.0.50.0210.03247.85
7.0.40.0300.04747.94
7.0.30.0550.04948.00
7.0.20.0560.04647.87
7.0.10.0120.02847.73
7.0.00.0080.03547.83
5.6.380.0300.05079.27
5.6.370.0360.03679.38
5.6.360.0370.04179.21
5.6.350.0340.05178.84
5.6.340.0330.04679.29
5.6.330.0330.04378.90
5.6.320.0300.04479.14
5.6.310.0300.04479.01
5.6.300.0530.02578.70
5.6.290.0430.02679.34
5.6.280.0320.07982.42
5.6.270.0430.04079.15
5.6.260.0350.03579.36
5.6.250.0240.05179.30
5.6.240.0480.04879.35
5.6.230.0280.04979.21
5.6.220.0260.04378.97
5.6.210.0420.06982.03
5.6.200.0320.07480.99
5.6.190.0180.07481.94
5.6.180.0460.07881.95
5.6.170.0380.06182.16
5.6.160.0430.05682.01
5.6.150.0330.08480.84
5.6.140.0230.07581.07
5.6.130.0320.06480.92
5.6.120.0360.07582.37
5.6.110.0260.08682.36
5.6.100.0270.06782.44
5.6.90.0430.06882.36
5.6.80.0150.06881.95
5.6.70.0410.03878.79
5.6.60.0420.04578.98
5.6.50.0320.03979.29
5.6.40.0360.04078.88
5.6.30.0380.03578.81
5.6.20.0280.04778.89
5.6.10.0230.05079.03
5.6.00.0320.03878.98
5.5.380.0470.03775.96
5.5.370.0310.04476.04
5.5.360.0360.03375.85
5.5.350.2330.05680.47
5.5.340.0340.07879.30
5.5.330.0360.07780.36
5.5.320.0360.07880.35
5.5.310.0360.08180.41
5.5.300.0270.05279.34
5.5.290.0410.06479.24
5.5.280.0300.07280.69
5.5.270.0330.05580.73
5.5.260.0300.08280.64
5.5.250.0230.05980.58
5.5.240.0340.07480.33
5.5.230.0460.02975.60
5.5.220.0320.03975.66
5.5.210.0200.05775.92
5.5.200.0340.04175.63
5.5.190.0330.04375.93
5.5.180.0270.05175.91
5.5.170.0490.02678.96
5.5.160.0310.03775.71
5.5.150.0320.04275.96
5.5.140.0340.04075.85
5.5.130.0280.04475.61
5.5.120.0420.03175.92
5.5.110.0290.04675.65
5.5.100.0280.04175.70
5.5.90.0320.03975.56
5.5.80.0340.03375.93
5.5.70.0300.04075.82
5.5.60.0310.04175.94
5.5.50.0410.03275.66
5.5.40.0330.03475.71
5.5.30.0370.03375.74
5.5.20.0270.04475.93
5.5.10.0200.05075.74
5.5.00.0330.03675.69
5.4.450.0470.05479.91
5.4.440.0620.06079.94
5.4.430.0380.06079.88
5.4.420.0820.05579.75
5.4.410.0330.06879.73
5.4.400.0430.06379.77
5.4.390.0390.06179.76
5.4.380.0510.07979.46
5.4.370.0540.07779.63
5.4.360.0540.06279.54
5.4.350.0500.08979.42
5.4.340.0470.07079.33
5.4.330.0380.04175.62
5.4.320.0230.06376.62
5.4.310.0310.05176.42
5.4.300.0270.06276.58
5.4.290.0270.06176.42
5.4.280.0320.05876.38
5.4.270.0300.06176.34
5.4.260.0340.05976.40
5.4.250.0330.07576.41
5.4.240.0380.06476.26
5.4.230.0350.06676.39
5.4.220.0280.06676.41
5.4.210.0310.06176.51
5.4.200.0290.06176.38
5.4.190.0250.06376.50
5.4.180.0240.06076.39
5.4.170.0280.05776.38
5.4.160.0320.05276.48
5.4.150.0250.06176.39
5.4.140.0320.06076.24
5.4.130.0360.05176.21
5.4.120.0340.06276.12
5.4.110.0340.06776.35
5.4.100.0300.06276.33
5.4.90.0240.06676.26
5.4.80.0280.06776.19
5.4.70.0210.06776.28
5.4.60.0360.05876.31
5.4.50.0260.06376.21
5.4.40.0220.06776.28
5.4.30.0290.07276.19
5.4.20.0320.06476.21
5.4.10.0360.06376.30
5.4.00.0330.06675.92
5.3.290.0070.03211.94
5.3.280.0110.02411.89
5.3.270.0100.02611.90
5.3.260.0100.03111.90
5.3.250.0090.02911.90
5.3.240.0110.02811.90
5.3.230.0070.02911.89
5.3.220.0080.02811.88
5.3.210.0060.03111.88
5.3.200.0120.04211.88
5.3.190.0090.02511.88
5.3.180.0080.03011.88
5.3.170.0100.02511.87
5.3.160.0090.02711.88
5.3.150.0090.02911.87
5.3.140.0080.03211.87
5.3.130.0100.02911.87
5.3.120.0110.02611.87
5.3.110.0050.02911.87
5.3.100.0070.02711.60
5.3.90.0090.02711.59
5.3.80.0080.02611.59
5.3.70.0110.02111.59
5.3.60.0060.02311.57
5.3.50.0080.02111.55
5.3.40.0100.02811.55
5.3.30.0100.01911.53
5.3.20.0060.02311.42
5.3.10.0100.02011.40
5.3.00.0060.02411.40
5.2.170.0070.02310.15
5.2.160.0060.02010.15
5.2.150.0040.02510.15
5.2.140.0090.01610.15
5.2.130.0050.01910.13
5.2.120.0090.01510.13
5.2.110.0020.01910.13
5.2.100.0050.02110.13
5.2.90.0060.01810.13
5.2.80.0090.02010.13
5.2.70.0080.02110.13
5.2.60.0070.01810.10
5.2.50.0050.01910.09
5.2.40.0080.01710.08
5.2.30.0040.01910.06
5.2.20.0080.01910.06
5.2.10.0060.01810.01
5.2.00.0040.0229.94
5.1.60.0080.0179.59
5.1.50.0050.0189.58
5.1.40.0050.0199.58
5.1.30.0070.0189.75
5.1.20.0040.0229.76
5.1.10.0070.0179.63
5.1.00.0070.0199.62
5.0.50.0070.0098.86
5.0.40.0080.0128.79
5.0.30.0050.0208.70
5.0.20.0020.0168.68
5.0.10.0020.0188.67
5.0.00.0050.0208.66
4.4.90.0030.0137.93
4.4.80.0040.0127.91
4.4.70.0040.0107.92
4.4.60.0060.0117.92
4.4.50.0050.0137.92
4.4.40.0040.0197.89
4.4.30.0020.0157.92
4.4.20.0040.0097.96
4.4.10.0020.0117.96
4.4.00.0020.0187.92
4.3.110.0020.0127.87
4.3.100.0050.0117.87
4.3.90.0060.0117.85
4.3.80.0030.0187.83
4.3.70.0050.0117.85
4.3.60.0030.0107.85
4.3.50.0050.0107.85
4.3.40.0040.0167.80
4.3.30.0040.0117.19
4.3.20.0040.0117.18
4.3.10.0020.0127.16
4.3.00.0050.00716.26

preferences:
42.16 ms | 401 KiB | 5 Q