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(2, self::OneThousand, 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.0110.01116.50
8.3.50.0090.01622.01
8.3.40.0100.00718.83
8.3.30.0000.01819.13
8.3.20.0060.00320.34
8.3.10.0050.00523.83
8.3.00.0060.00319.11
8.2.180.0120.00616.63
8.2.170.0130.00622.96
8.2.160.0070.01020.53
8.2.150.0030.00624.18
8.2.140.0030.00624.66
8.2.130.0050.00526.16
8.2.120.0050.00520.55
8.2.110.0070.01119.31
8.2.100.0110.00317.91
8.2.90.0030.00719.17
8.2.80.0030.00717.97
8.2.70.0080.00317.63
8.2.60.0090.00717.55
8.2.50.0050.00518.07
8.2.40.0030.00719.88
8.2.30.0030.00618.34
8.2.20.0000.01117.70
8.2.10.0000.01018.10
8.2.00.0030.00717.73
8.1.280.0110.01425.92
8.1.270.0070.00323.79
8.1.260.0060.00326.35
8.1.250.0000.00928.09
8.1.240.0040.00722.02
8.1.230.0070.00720.90
8.1.220.0040.00717.74
8.1.210.0070.00318.77
8.1.200.0000.01317.35
8.1.190.0070.00317.22
8.1.180.0060.00618.10
8.1.170.0000.01018.57
8.1.160.0000.01021.99
8.1.150.0000.01118.72
8.1.140.0000.01017.50
8.1.130.0000.00917.86
8.1.120.0070.00317.54
8.1.110.0070.00317.51
8.1.100.0070.00317.51
8.1.90.0000.00917.54
8.1.80.0000.01117.57
8.1.70.0100.00017.53
8.1.60.0040.00717.52
8.1.50.0070.00417.57
8.1.40.0030.00817.41
8.1.30.0030.00817.69
8.1.20.0030.00717.73
8.1.10.0040.00717.53
8.1.00.0030.00717.55
8.0.300.0030.00618.77
8.0.290.0080.00316.88
8.0.280.0030.00718.38
8.0.270.0000.00917.35
8.0.260.0030.00617.23
8.0.250.0060.00316.89
8.0.240.0040.00716.88
8.0.230.0000.00916.94
8.0.220.0040.00416.97
8.0.210.0090.00016.93
8.0.200.0030.00616.96
8.0.190.0030.00817.04
8.0.180.0000.01116.93
8.0.170.0050.00516.88
8.0.160.0040.00816.82
8.0.150.0070.00416.88
8.0.140.0000.01016.94
8.0.130.0040.00413.42
8.0.120.0000.01116.89
8.0.110.0030.00716.96
8.0.100.0030.00616.98
8.0.90.0030.00716.95
8.0.80.0100.01317.00
8.0.70.0000.01016.75
8.0.60.0060.00316.95
8.0.50.0000.01116.98
8.0.30.0080.01617.03
8.0.20.0150.02017.40
8.0.10.0030.00617.05
8.0.00.0080.01616.73
7.4.330.0020.00515.00
7.4.320.0000.00916.58
7.4.300.0060.00316.54
7.4.290.0030.00716.59
7.4.280.0000.01016.65
7.4.270.0070.00316.66
7.4.260.0000.01316.54
7.4.250.0030.00716.48
7.4.240.0020.00916.64
7.4.230.0000.01016.66
7.4.220.0160.02216.45
7.4.210.0030.01616.66
7.4.200.0000.01016.74
7.4.190.0060.00316.71
7.4.160.0060.02516.58
7.4.150.0100.01717.40
7.4.140.0100.01817.86
7.4.130.0090.01716.54
7.4.120.0110.01416.49
7.4.110.0070.01516.52
7.4.100.0060.01816.57
7.4.90.0100.02116.61
7.4.80.0060.02019.39
7.4.70.0100.01316.76
7.4.60.0060.01716.48
7.4.50.0100.00316.52
7.4.40.0090.01316.48
7.4.30.0060.01616.36
7.4.10.0100.01315.25
7.4.00.0080.01315.03
7.3.330.0060.00313.42
7.3.320.0030.00613.22
7.3.310.0030.00716.45
7.3.300.0070.00416.29
7.3.290.0100.01016.44
7.3.280.0090.01916.38
7.3.270.0050.01817.40
7.3.260.0130.01316.46
7.3.250.0100.01816.57
7.3.240.0160.01616.42
7.3.230.0070.02416.39
7.3.210.0070.02216.41
7.3.200.0070.01719.39
7.3.190.0080.01616.68
7.3.180.0160.00616.61
7.3.170.0180.00616.71
7.3.160.0060.01616.59
7.3.130.0030.02115.05
7.3.120.0100.01015.04
7.3.110.0030.02114.77
7.3.100.0100.01015.18
7.3.90.0060.01214.95
7.3.80.0030.01414.95
7.3.70.0000.01814.84
7.3.60.0100.01015.05
7.3.50.0070.00714.84
7.3.40.0070.01014.65
7.3.30.0070.01115.03
7.3.20.0090.00616.75
7.3.10.0050.01616.79
7.3.00.0080.00916.70
7.2.330.0130.02016.80
7.2.320.0040.02316.71
7.2.310.0100.01316.82
7.2.300.0140.01116.59
7.2.290.0060.01916.64
7.2.260.0000.02415.13
7.2.250.0140.00915.26
7.2.240.0030.01715.04
7.2.230.0040.01515.30
7.2.220.0030.01615.01
7.2.210.0100.01015.28
7.2.200.0000.02015.09
7.2.190.0070.01114.99
7.2.180.0120.00915.14
7.2.170.0090.01215.06
7.2.160.0030.01315.00
7.2.150.0100.00316.71
7.2.140.0150.00616.77
7.2.130.0120.00617.09
7.2.120.0080.01016.68
7.2.110.0090.00916.81
7.2.100.0070.01316.73
7.2.90.0030.01416.78
7.2.80.0090.00617.07
7.2.70.0080.01116.87
7.2.60.0100.01117.08
7.2.50.0090.01117.10
7.2.40.0040.01617.06
7.2.30.0060.01417.15
7.2.20.0030.01616.85
7.2.10.0030.01317.02
7.2.00.0030.01617.86
7.1.330.0030.02116.04
7.1.320.0070.01615.88
7.1.310.0030.02015.93
7.1.300.0030.01715.85
7.1.290.0070.01715.67
7.1.280.0030.02015.95
7.1.270.0070.02015.77
7.1.260.0030.02415.69
7.1.250.0050.01915.98
7.1.240.0060.01815.93
7.1.230.0070.01715.55
7.1.220.0060.01915.93
7.1.210.0070.01715.64
7.1.200.0070.01315.84
7.1.190.0040.01815.93
7.1.180.0090.01315.78
7.1.170.0070.02015.83
7.1.160.0070.02315.61
7.1.150.0030.02415.76
7.1.140.0000.02415.90
7.1.130.0100.01915.81
7.1.120.0060.01615.62
7.1.110.0060.02215.86
7.1.100.0030.01616.96
7.1.90.0090.01515.54
7.1.80.0030.01815.62
7.1.70.0030.01716.41
7.1.60.0050.02317.64
7.1.50.0070.01816.48
7.1.40.0070.01615.57
7.1.30.0100.01615.78
7.1.20.0030.01815.78
7.1.10.0000.02215.93
7.1.00.0080.04719.08
7.0.330.0000.01815.40
7.0.320.0100.01315.21
7.0.310.0030.02115.33
7.0.300.0090.00915.36
7.0.290.0090.01515.57
7.0.280.0030.02015.52
7.0.270.0030.02615.45
7.0.260.0060.01915.51
7.0.250.0030.01715.20
7.0.240.0100.01315.22
7.0.230.0030.02415.59
7.0.220.0090.01815.54
7.0.210.0000.02315.25
7.0.200.0020.01616.10
7.0.190.0060.01915.30
7.0.180.0100.02015.46
7.0.170.0030.01715.45
7.0.160.0070.01615.50
7.0.150.0080.01915.55
7.0.140.0050.04918.70
7.0.130.0030.02215.57
7.0.120.0070.01415.20
7.0.110.0070.01715.56
7.0.100.0070.01515.30
7.0.90.0060.01615.54
7.0.80.0000.02415.43
7.0.70.0000.01815.68
7.0.60.0060.04317.76
7.0.50.0070.05016.75
7.0.40.0030.04716.85
7.0.30.0150.03316.84
7.0.20.0220.03216.80
7.0.10.0030.05516.87
7.0.00.0100.04916.81
5.6.400.0030.03914.73
5.6.390.0000.03114.77
5.6.380.0030.03414.71
5.6.370.0030.02714.59
5.6.360.0030.02814.65
5.6.350.0100.03214.40
5.6.340.0030.02914.56
5.6.330.0030.03514.66
5.6.320.0030.03214.65
5.6.310.0000.02914.84
5.6.300.0100.02614.40
5.6.290.0070.03314.73
5.6.280.0030.06117.80
5.6.270.0070.03014.85
5.6.260.0030.03114.76
5.6.250.0070.02714.66
5.6.240.0070.03014.39
5.6.230.0100.02614.50
5.6.220.0070.02714.63
5.6.210.0110.04617.54
5.6.200.0050.04416.46
5.6.190.0070.04517.45
5.6.180.0060.03917.44
5.6.170.0170.03917.48
5.6.160.0030.04717.62
5.6.150.0030.05916.52
5.6.140.0030.04416.35
5.6.130.0020.04916.28
5.6.120.0030.04117.87
5.6.110.0060.04517.82
5.6.100.0120.05917.75
5.6.90.0080.05517.65
5.6.80.0020.06117.48
5.6.70.0030.03114.61
5.6.60.0060.02914.57
5.6.50.0000.02914.64
5.6.40.0100.02614.36
5.6.30.0030.04014.68
5.6.20.0030.03614.60
5.6.10.0000.03514.53
5.6.00.0030.03814.42
5.5.380.0070.03014.65
5.5.370.0060.03814.71
5.5.360.0030.02814.74
5.5.350.1400.03517.54
5.5.340.0050.04116.20
5.5.330.0110.05917.51
5.5.320.0220.05517.40
5.5.310.0220.05617.44
5.5.300.0070.04616.39
5.5.290.0050.05916.09
5.5.280.0050.04017.67
5.5.270.0050.04617.70
5.5.260.0030.05817.85
5.5.250.0030.04017.61
5.5.240.0030.05517.47
5.5.230.0000.03914.45
5.5.220.0070.02814.30
5.5.210.0130.02314.55
5.5.200.0030.03414.26
5.5.190.0000.04214.54
5.5.180.0070.02414.46
5.5.170.0000.03614.51
5.5.160.0060.02914.39
5.5.150.0030.03514.57
5.5.140.0070.02514.62
5.5.130.0000.03414.52
5.5.120.0030.03314.58
5.5.110.0090.03114.52
5.5.100.0070.03114.58
5.5.90.0070.02714.42
5.5.80.0100.02914.53
5.5.70.0070.03014.59
5.5.60.0100.02614.24
5.5.50.0100.03114.43
5.5.40.0070.02814.47
5.5.30.0100.02414.54
5.5.20.0070.02614.43
5.5.10.0000.03614.55
5.5.00.0100.02614.29
5.4.450.0160.04225.26
5.4.440.0100.04222.75
5.4.430.0120.04420.49
5.4.420.0200.04419.89
5.4.410.0130.04018.87
5.4.400.0120.03918.16
5.4.390.0150.04117.29
5.4.380.0220.06015.78
5.4.370.0280.04215.90
5.4.360.0170.04915.91
5.4.350.0130.05615.79
5.4.340.0170.04715.88
5.4.330.0070.02712.98
5.4.320.0100.03912.79
5.4.310.0040.03712.78
5.4.300.0070.04812.79
5.4.290.0030.05312.79
5.4.280.0080.04612.73
5.4.270.0100.04212.74
5.4.260.0070.04812.74
5.4.250.0040.05112.74
5.4.240.0040.05112.73
5.4.230.0060.04912.73
5.4.220.0070.04612.73
5.4.210.0040.04912.73
5.4.200.0050.04912.73
5.4.190.0050.04912.73
5.4.180.0050.04712.73
5.4.170.0080.04912.73
5.4.160.0050.04112.73
5.4.150.0050.04112.73
5.4.140.0070.03812.57
5.4.130.0050.04512.56
5.4.120.0080.03812.54
5.4.110.0050.03912.54
5.4.100.0050.04112.54
5.4.90.0070.04712.54
5.4.80.0080.04612.54
5.4.70.0080.04512.54
5.4.60.0060.04212.54
5.4.50.0070.04012.54
5.4.40.0050.03912.54
5.4.30.0040.03812.53
5.4.20.0050.04012.53
5.4.10.0060.04012.53
5.4.00.0040.04412.28
5.3.290.0040.02512.89
5.3.280.0060.02512.84
5.3.270.0060.02712.85
5.3.260.0050.02812.85
5.3.250.0090.02412.85
5.3.240.0050.02812.85
5.3.230.0070.02712.84
5.3.220.0050.02812.83
5.3.210.0080.02512.83
5.3.200.0100.02212.83
5.3.190.0050.02412.83
5.3.180.0100.01912.82
5.3.170.0050.02612.82
5.3.160.0040.02512.83
5.3.150.0060.02012.83
5.3.140.0050.02312.82
5.3.130.0060.02212.82
5.3.120.0050.02212.82
5.3.110.0050.02212.82
5.3.100.0060.02012.55
5.3.90.0050.02312.54
5.3.80.0050.02012.54
5.3.70.0040.03212.54
5.3.60.0050.02812.53
5.3.50.0040.02512.50
5.3.40.0090.01712.50
5.3.30.0060.01912.48
5.3.20.0060.02212.37
5.3.10.0030.02212.35
5.3.00.0070.02412.35
5.2.170.0060.0369.22
5.2.160.0070.0299.22
5.2.150.0050.0399.22
5.2.140.0050.0369.22
5.2.130.0070.0309.19
5.2.120.0050.0329.18
5.2.110.0030.0349.19
5.2.100.0070.0309.18
5.2.90.0050.0339.18
5.2.80.0050.0329.18
5.2.70.0050.0329.18
5.2.60.0050.0329.14
5.2.50.0040.0339.10
5.2.40.0080.0279.08
5.2.30.0040.0319.05
5.2.20.0040.0339.05
5.2.10.0110.0258.96
5.2.00.0060.0308.81
5.1.60.0040.0268.10
5.1.50.0080.0248.09
5.1.40.0040.0288.08
5.1.30.0060.0348.42
5.1.20.0060.0368.45
5.1.10.0080.0298.17
5.1.00.0090.0328.17
5.0.50.0020.0326.65
5.0.40.0050.0326.51
5.0.30.0050.0446.32
5.0.20.0030.0296.29
5.0.10.0050.0286.27
5.0.00.0060.0376.25
4.4.90.0030.0234.78
4.4.80.0030.0234.75
4.4.70.0020.0194.75
4.4.60.0020.0154.76
4.4.50.0020.0154.77
4.4.40.0020.0254.71
4.4.30.0030.0154.76
4.4.20.0050.0134.84
4.4.10.0050.0134.85
4.4.00.0010.0284.76
4.3.110.0020.0184.67
4.3.100.0030.0184.67
4.3.90.0020.0234.63
4.3.80.0030.0264.59
4.3.70.0040.0134.63
4.3.60.0020.0154.63
4.3.50.0030.0164.62
4.3.40.0070.0374.53
4.3.30.0000.0253.30
4.3.20.0030.0203.29
4.3.10.0010.0253.24
4.3.00.0000.02021.40

preferences:
43.28 ms | 401 KiB | 5 Q