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; //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){ $this->evenNumbers = range(16, self::OneMillion, 2); } public function processEvenNumbers() { $commonFactors = $this->calcFactors($this->getClosestEvenToZero($this->startInt, $this->endInt, $this->evenNumbers)); foreach($this->evenNumbers as $evenNumber){ $commonFactors = $this->checkIfHasCommonFactors($evenNumber, $commonFactors); } return array_sum($commonFactors); } protected function getClosestEvenToZero($startInt, $endInt, $evenNumbers){ $dist = abs($evenNumbers[0]); $idx = 0; $totalNo = count($evenNumbers); for($i=0;$i<$totalNo;$i++){ $newDist = abs($evenNumbers[$i]); if($newDist < $dist){ $idx = $i; $dist = $newDist; } if($dist == 0){//only if evenNumbers is sorted return $evenNumbers[$idx]; } } return $evenNumbers[$idx]; } protected function checkIfHasCommonFactors($int, array $minCommonFactors){ $int = abs($int); $cF = $this->calcFactors($int); return array_intersect($cF, $minCommonFactors); } private function calcFactors($int) { $int = abs($int); $cF = []; $max = $int/2; for($i=1;$i<=$max;$i++){ if(0 === $int%$i){ $cF[] = $i; } } $cF[] = $int; return $cF; } }

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.0201.98124.25
8.3.50.0101.99426.09
8.3.40.0071.99726.43
8.3.30.0201.98426.82
8.3.20.0101.99327.82
8.3.10.0031.99831.64
8.3.00.0131.99028.53
8.2.180.0201.98523.97
8.2.170.0171.98826.57
8.2.160.0071.99828.14
8.2.150.0201.98327.02
8.2.140.0131.99029.05
8.2.130.0071.99730.26
8.2.120.0031.99928.97
8.2.110.0031.99926.81
8.2.100.0171.98625.34
8.2.90.0031.99826.84
8.2.80.0101.99327.08
8.2.70.0032.00125.38
8.2.60.0131.98825.91
8.2.50.0101.99925.25
8.2.40.0002.00127.98
8.2.30.0032.00026.11
8.2.20.0031.99925.43
8.2.10.0031.99925.91
8.2.00.0031.99925.65
8.1.280.0271.97731.23
8.1.270.0231.98139.21
8.1.260.0131.98735.93
8.1.250.0071.99737.39
8.1.240.0171.98737.56
8.1.230.0171.98633.20
8.1.220.0031.99933.04
8.1.210.0071.99632.60
8.1.200.0141.98932.63
8.1.190.0101.99532.60
8.1.180.0071.99532.60
8.1.170.0071.99633.75
8.1.160.0071.99737.44
8.1.150.0231.98434.00
8.1.140.0101.99232.88
8.1.130.0071.99733.29
8.1.120.0101.99232.89
8.1.110.0101.99432.77
8.1.100.0071.99732.77
8.1.90.0071.99732.92
8.1.80.0032.00032.76
8.1.70.0131.98932.77
8.1.60.0032.00133.01
8.1.50.0071.99832.89
8.1.40.0171.98632.93
8.1.30.0101.99233.00
8.1.20.0101.99633.07
8.1.10.0131.98932.91
8.1.00.0131.98832.91
8.0.300.0131.99131.97
8.0.290.0101.99231.75
8.0.280.0071.99633.75
8.0.270.0131.99232.61
8.0.260.0071.99632.67
8.0.250.0071.99832.29
8.0.240.0032.00032.33
8.0.230.0101.99432.13
8.0.220.0071.99632.24
8.0.210.0002.00432.07
8.0.200.0071.99832.21
8.0.190.0071.99932.15
8.0.180.0101.99232.19
8.0.170.0072.00032.24
8.0.160.0171.98732.18
8.0.150.0032.00032.17
8.0.140.0101.99432.18
8.0.130.0071.99428.73
8.0.120.0032.00232.13
8.0.110.0032.00032.20
8.0.100.0101.99332.16
8.0.90.0002.00732.24
8.0.80.0201.98132.11
8.0.70.0032.00132.18
8.0.60.0071.99832.20
8.0.50.0071.99832.17
8.0.30.0311.96332.43
8.0.20.0291.97132.51
8.0.10.0101.99232.27
8.0.00.0231.98032.02
7.4.330.0071.99830.35
7.4.320.0071.99731.86
7.4.300.0071.99831.73
7.4.290.0071.99631.80
7.4.280.0101.99531.75
7.4.270.0101.99531.82
7.4.260.0271.99231.80
7.4.250.0131.99231.64
7.4.240.0101.99431.66
7.4.230.0032.00331.86
7.4.220.0551.94731.64
7.4.210.0151.98731.86
7.4.200.0071.99731.91
7.4.190.0071.99731.55
7.4.160.0231.98031.97
7.4.150.0261.98731.84
7.4.140.0281.98131.74
7.4.130.0171.98531.76
7.4.120.0291.97131.78
7.4.110.0262.43031.93
7.4.100.0422.43431.90
7.4.90.0302.41131.80
7.4.80.0422.39831.82
7.4.70.0232.42831.54
7.4.60.0332.39931.88
7.4.50.0102.48931.88
7.4.40.0262.44431.82
7.4.30.0792.33131.74
7.4.00.0072.49130.29
7.3.330.0071.99728.68
7.3.320.0071.99528.58
7.3.310.0101.99331.65
7.3.300.0071.99631.55
7.3.290.0481.93431.68
7.3.280.0381.97331.66
7.3.270.0161.99131.65
7.3.260.0291.96931.96
7.3.250.0311.97931.74
7.3.240.0261.97631.85
7.3.230.0262.44731.64
7.3.210.0262.42431.48
7.3.200.0202.45531.73
7.3.190.0262.38931.86
7.3.180.0302.41131.80
7.3.170.0232.44931.79
7.3.160.0262.42331.59
7.3.120.0202.47330.17
7.2.330.0262.43431.66
7.2.320.0392.10431.76
7.2.310.0292.37932.21
7.2.300.0202.45732.08
7.2.290.0322.40632.00
7.2.60.0002.48832.58
7.2.00.0072.49435.36
7.1.200.0132.48331.71
7.1.100.0032.49834.28
7.1.70.1602.33632.93
7.1.60.0132.48833.37
7.1.50.0072.49533.10
7.1.00.0102.49038.27
7.0.200.0232.47832.63
7.0.140.0032.49738.00
7.0.60.0102.49035.25
7.0.50.3802.12033.18
7.0.40.1132.38735.04
7.0.30.0472.45334.98
7.0.20.0532.44735.05
7.0.10.0202.48035.20
7.0.00.0072.49335.10
5.6.280.0200.12385.70
5.6.210.0300.13085.23
5.6.200.0400.07082.66
5.6.190.0330.08084.89
5.6.180.0700.08085.16
5.6.170.0530.12085.06
5.6.160.0230.13085.00
5.6.150.0200.07082.82
5.6.140.0300.11082.89
5.6.130.0400.06782.85
5.6.120.0370.11385.68
5.6.110.0430.05785.66
5.6.100.0230.07085.67
5.6.90.0330.12785.77
5.6.80.0300.09085.04
5.5.350.4300.08385.03
5.5.340.0270.12382.61
5.5.330.0200.07084.81
5.5.320.0330.07384.81
5.5.310.0330.10084.79
5.5.300.0470.10382.62
5.5.290.0370.09082.64
5.5.280.0270.13085.54
5.5.270.0230.11385.42
5.5.260.0230.08785.59
5.5.250.0470.10385.13
5.5.240.0330.10784.70
5.4.450.0500.08384.23
5.4.440.0600.08084.04
5.4.430.0630.08084.01
5.4.420.0730.09083.73
5.4.410.0530.09383.73
5.4.400.0200.09383.44
5.4.390.0500.09083.69
5.4.380.0900.12083.43
5.4.370.0900.11083.44
5.4.360.0630.11783.29
5.4.350.0930.09383.17
5.4.340.0830.09783.30
5.4.320.0200.06977.22
5.4.310.0290.06877.22
5.4.300.0250.07377.23
5.4.290.0240.07477.21
5.4.280.0210.08377.12
5.4.270.0210.08277.12
5.4.260.0210.07177.12
5.4.250.0300.07377.12
5.4.240.0380.07677.12
5.4.230.0440.09077.11
5.4.220.0490.07477.11
5.4.210.0310.09277.11
5.4.200.0220.11277.11
5.4.190.0290.09177.10
5.4.180.0250.08177.11
5.4.170.0240.07877.11
5.4.160.0300.08677.11
5.4.150.0280.08177.11
5.4.140.0260.07776.79
5.4.130.0310.08776.78
5.4.120.0300.08476.74
5.4.110.0400.08676.73
5.4.100.0320.08776.73
5.4.90.0230.10076.73
5.4.80.0220.08776.73
5.4.70.0270.08876.73
5.4.60.0370.06276.73
5.4.50.0240.07476.73
5.4.40.0220.07776.72
5.4.30.0330.08376.71
5.4.20.0390.09276.71
5.4.10.0320.10076.71
5.4.00.0240.10776.20
5.3.290.0070.04412.80
5.3.280.0090.04812.71
5.3.270.0080.05012.72
5.3.260.0120.03612.72
5.3.250.0050.04112.72
5.3.240.0080.03912.71
5.3.230.0050.04112.71
5.3.220.0080.03812.68
5.3.210.0090.03712.68
5.3.200.0080.05212.68
5.3.190.0160.04612.68
5.3.180.0100.05212.67
5.3.170.0060.05612.67
5.3.160.0120.04912.68
5.3.150.0050.03912.68
5.3.140.0060.04112.66
5.3.130.0090.03712.66
5.3.120.0060.04212.66
5.3.110.0070.04012.66
5.3.100.0040.03912.12
5.3.90.0020.04212.11
5.3.80.0110.03812.09
5.3.70.0070.04112.10
5.3.60.0050.05012.08
5.3.50.0090.04912.03
5.3.40.0090.03912.03
5.3.30.0050.03511.98
5.3.20.0070.04111.77
5.3.10.0050.04611.73
5.3.00.0070.03811.72
5.2.170.0070.0359.22
5.2.160.0080.0279.22
5.2.150.0050.0459.23
5.2.140.0090.0399.22
5.2.130.0100.0409.18
5.2.120.0070.0339.19
5.2.110.0120.0409.19
5.2.100.0140.0449.18
5.2.90.0190.0599.18
5.2.80.0070.0409.18
5.2.70.0090.0519.18
5.2.60.0090.0469.13
5.2.50.0070.0419.10
5.2.40.0040.0419.08
5.2.30.0040.0449.05
5.2.20.0090.0269.05
5.2.10.0070.0268.95
5.2.00.0060.0288.82
5.1.60.0050.0238.10
5.1.50.0060.0238.09
5.1.40.0050.0258.07
5.1.30.0040.0288.42
5.1.20.0030.0288.45
5.1.10.0050.0488.17
5.1.00.0050.0308.18
5.0.50.0040.0226.65
5.0.40.0050.0196.50
5.0.30.0020.0406.32
5.0.20.0040.0216.29
5.0.10.0030.0296.27
5.0.00.0050.0396.25
4.4.90.0050.0214.78
4.4.80.0040.0184.75
4.4.70.0020.0194.76
4.4.60.0050.0214.75
4.4.50.0030.0164.77
4.4.40.0010.0284.71
4.4.30.0040.0164.76
4.4.20.0050.0144.84
4.4.10.0060.0134.85
4.4.00.0020.0274.76
4.3.110.0050.0174.67
4.3.100.0010.0224.66
4.3.90.0030.0154.64
4.3.80.0030.0254.58
4.3.70.0070.0124.63
4.3.60.0050.0154.63
4.3.50.0050.0204.63
4.3.40.0010.0304.54
4.3.30.0030.0193.31
4.3.20.0030.0173.29
4.3.10.0030.0163.24
4.3.00.0030.01721.99

preferences:
43.78 ms | 401 KiB | 5 Q