3v4l.org

run code in 300+ PHP versions simultaneously
<?php $hotels = [ ['Cala', 3, 8.7, 6000], ['Ocean', 3, 8.2, 6150], ['Orchid', 3, 8.0, 7200], ['Ya', 4, 8.3, 6950], ['Chaba', 3, 8.2, 7120], ]; $top = [ 'Ya', 'Cala', 'Ocean', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0.02, 5, 0.02); $ratingCoefOptions = range(50, 10000, 50); foreach ( $starCoefOptions as $starCoef ) { foreach ( $ratingCoefOptions as $ratingCoef ) { $topGenerated = buildTop($hotels, $starCoef, $ratingCoef); $topGenerated = array_slice($topGenerated, 0, count($top)); if ( $topGenerated === $top ) { echo '$starCoef = '.$starCoef."\r\n"; echo '$ratingCoef = '.$ratingCoef."\r\n"; echo "\r\n"; } } } function buildTop($hotels, $starCoef, $ratingCoef) { for ( $i=0; $i<count($hotels); $i++ ) { for ( $j=$i+1; $j<count($hotels); $j++ ) { $starDifference = $hotels[$i][1]-$hotels[$j][1]; $ratingToCompensate = $starDifference*$starCoef; $rating = $hotels[$i][2]+$ratingToCompensate; $ratingDifference = ($rating-$hotels[$j][2])*10; $priceToCompensate = $ratingDifference*$ratingCoef; $price = round($hotels[$i][3]-$priceToCompensate); if ( $price < $hotels[$j][3] ) { $hotels[$i][4]++; } else { $hotels[$j][4]++; } } } usort($hotels, function($hotelA, $hotelB){ return $hotelB[4]-$hotelA[4]; }); return array_map(function($hotel){ return $hotel[0]; }, $hotels); }

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.0190.04118.43
8.3.50.0180.04122.17
8.3.40.0130.02918.95
8.3.30.0170.02419.10
8.3.20.0160.01319.04
8.3.10.0110.02121.20
8.3.00.0200.01323.91
8.2.180.0290.03316.75
8.2.170.0200.04022.96
8.2.160.0160.02620.46
8.2.150.0190.01924.18
8.2.140.0070.02124.66
8.2.130.0090.01926.16
8.2.120.0070.02321.19
8.2.110.0070.02419.51
8.1.280.0190.03925.92
8.1.270.0090.01223.99
8.1.260.0100.01926.35
8.1.250.0110.01828.09
8.1.240.0230.02017.50
7.4.10.0200.07515.34
7.4.00.0140.06315.35
7.3.130.0130.08114.93
7.3.120.0100.06915.02
7.3.110.0070.07815.46
7.3.100.0070.06415.44
7.3.90.0070.05015.21
7.3.80.0130.05015.45
7.3.70.0170.05214.84
7.3.60.0100.05515.26
7.3.50.0170.04415.10
7.3.40.0100.04215.39
7.3.30.0030.04815.16
7.3.20.0100.05816.95
7.3.10.0100.06416.95
7.3.00.0070.04616.89
7.2.260.0200.07315.60
7.2.250.0130.06015.37
7.2.240.0030.05515.46
7.2.230.0000.07315.66
7.2.220.0030.07415.64
7.2.210.0170.05815.53
7.2.200.0000.08015.28
7.2.190.0070.05315.61
7.2.180.0130.04915.53
7.2.170.0100.06015.61
7.2.160.0000.07515.53
7.2.150.0030.07417.19
7.2.140.0060.05817.20
7.2.130.0070.06417.25
7.2.120.0160.04917.13
7.2.110.0100.05217.28
7.2.100.0160.04617.23
7.2.90.0070.07417.25
7.2.80.0070.05717.34
7.2.70.0260.03617.32
7.2.60.0200.05617.18
7.2.50.0130.05817.14
7.2.40.0070.05717.38
7.2.30.0030.05917.11
7.2.20.0130.07317.38
7.2.10.0160.03917.34
7.2.00.0070.06617.31
7.1.330.0000.08616.00
7.1.320.0270.06916.00
7.1.310.0170.07116.01
7.1.300.0160.08916.13
7.1.290.0070.06516.13
7.1.280.0170.05715.92
7.1.270.0070.07816.10
7.1.260.0130.07816.17
7.1.250.0030.07716.15
7.1.240.0030.08816.06
7.1.230.0030.08716.19
7.1.220.0100.07916.04
7.1.210.0030.08415.96
7.1.200.0230.09316.25
7.1.190.0130.08416.39
7.1.180.0140.09016.17
7.1.170.0070.06616.14
7.1.160.0030.08616.39
7.1.150.0140.07116.16
7.1.140.0200.07616.05
7.1.130.0130.08415.90
7.1.120.0100.07916.39
7.1.110.0170.07816.13
7.1.100.0170.09915.86
7.1.90.0100.06415.98
7.1.80.0030.07916.34
7.1.70.0130.08516.13
7.1.60.0130.10816.21
7.1.50.0170.08016.28
7.1.40.0030.08316.03
7.1.30.0130.10116.26
7.1.20.0130.08816.13
7.1.10.0200.08215.93
7.1.00.0030.07316.15
7.0.330.0070.10315.85
7.0.320.0100.08215.82
7.0.310.0070.07915.48
7.0.300.0170.08515.91
7.0.290.0130.09115.66
7.0.280.0100.06315.98
7.0.270.0100.06915.79
7.0.260.0030.08915.82
7.0.250.0130.09215.92
7.0.240.0170.09315.98
7.0.230.0030.08915.79
7.0.220.0170.09215.93
7.0.210.0130.08415.91
7.0.200.0160.07915.57
7.0.190.0120.10215.78
7.0.180.0100.07115.61
7.0.170.0190.08215.82
7.0.160.0160.08115.54
7.0.150.0130.09015.95
7.0.140.0100.07815.61
7.0.130.0100.08415.94
7.0.120.0140.08515.53
7.0.110.0070.10415.83
7.0.100.0120.07915.95
7.0.90.0240.08815.66
7.0.80.0030.08215.95
7.0.70.0070.07315.65
7.0.60.0070.07715.51
7.0.50.0000.09215.68
7.0.40.0100.07113.84
7.0.30.0130.08013.82
7.0.20.0130.10013.96
7.0.10.0130.07313.71
7.0.00.0030.08113.91
5.6.400.0070.15014.79
5.6.390.0160.14714.88
5.6.380.0130.16814.82
5.6.370.0100.15314.92
5.6.360.0100.12314.88
5.6.350.0130.13714.90
5.6.340.0070.16015.13
5.6.330.0030.12014.85
5.6.320.0070.14414.85
5.6.310.0100.17214.91
5.6.300.0100.16014.89
5.6.290.0070.14915.08
5.6.280.0130.15115.02
5.6.270.0070.17614.92
5.6.260.0100.14614.59
5.6.250.0100.15515.06
5.6.240.0070.16114.92
5.6.230.0100.15514.90
5.6.220.0200.13214.94
5.6.210.0070.16315.10
5.6.200.0130.16415.00
5.6.190.0070.15514.86
5.6.180.0070.15714.82
5.6.170.0030.17015.03
5.6.160.0030.14314.82
5.6.150.0070.15415.06
5.6.140.0070.14314.92
5.6.130.0160.16115.00
5.6.120.0230.13014.83
5.6.110.0100.13114.93
5.6.100.0100.15315.21
5.6.90.0100.12514.98
5.6.80.0130.16115.00
5.6.70.0130.15914.74
5.6.60.0130.14814.92
5.6.50.0130.14714.64
5.6.40.0230.13714.65
5.6.30.0200.15214.81
5.6.20.0100.14514.62
5.6.10.0100.14614.74
5.6.00.0170.15414.93
5.5.380.0030.15614.93
5.5.370.0100.16415.00
5.5.360.0130.15914.78
5.5.350.0200.16514.69
5.5.340.0160.15814.77
5.5.330.0100.16015.06
5.5.320.0030.18014.95
5.5.310.0130.15614.69
5.5.300.0100.16015.23
5.5.290.0200.14814.57
5.5.280.0070.15515.06
5.5.270.0070.13815.11
5.5.260.0200.16114.99
5.5.250.0030.16714.88
5.5.240.0030.18214.71
5.5.230.0130.15814.69
5.5.220.0200.15514.66
5.5.210.0100.16014.59
5.5.200.0070.14714.95
5.5.190.0170.15614.82
5.5.180.0100.16214.90
5.5.170.0130.15714.78
5.5.160.0130.15514.61
5.5.150.0100.14314.64
5.5.140.0070.13914.70
5.5.130.0070.14314.77
5.5.120.0070.16514.93
5.5.110.0130.14814.91
5.5.100.0030.16714.77
5.5.90.0100.14814.75
5.5.80.0160.15814.61
5.5.70.0030.13414.60
5.5.60.0160.12114.68
5.5.50.0130.16614.95
5.5.40.0100.14815.03
5.5.30.0100.14914.64
5.5.20.0060.16115.19
5.5.10.0100.15514.55
5.5.00.0160.17014.43
5.4.450.0130.16412.84
5.4.440.0070.14112.84
5.4.430.0030.14412.84
5.4.420.0070.16212.84
5.4.410.0070.14312.84
5.4.400.0100.16812.84
5.4.390.0030.17112.84
5.4.380.0100.15812.84
5.4.370.0100.16112.84
5.4.360.0100.12112.84
5.4.350.0070.12812.84
5.4.340.0000.16612.84
5.4.330.0070.16412.84
5.4.320.0130.15112.84
5.4.310.0100.14012.84
5.4.300.0170.15712.84
5.4.290.0030.13812.84
5.4.280.0050.16616.11
5.4.270.0130.16116.11
5.4.260.0080.14816.09
5.4.250.0080.15716.04
5.4.240.0070.17016.12
5.4.230.0100.16916.09
5.4.220.0130.14316.07
5.4.210.0070.15416.10
5.4.200.0100.15116.04
5.4.190.0120.15516.08
5.4.180.0200.13716.09
5.4.170.0120.15316.04
5.4.160.0150.15216.09
5.4.150.0170.13816.03
5.4.140.0110.15214.77
5.4.130.0130.15514.79
5.4.120.0100.13914.81
5.4.110.0080.17214.79
5.4.100.0080.14014.86
5.4.90.0150.15714.80
5.4.80.0150.14814.88
5.4.70.0220.15114.81
5.4.60.0050.15314.77
5.4.50.0100.18314.81
5.4.40.0170.14714.84
5.4.30.0100.14514.70
5.4.20.0080.16914.85
5.4.10.0150.18014.85
5.4.00.0150.18314.60
5.3.290.0040.00412.84
5.3.280.0030.04013.77
5.3.270.0040.02813.77
5.3.260.0020.04213.77
5.3.250.0030.02813.77
5.3.240.0050.03513.77
5.3.230.0050.01713.77
5.3.220.0030.02313.77
5.3.210.0030.04013.77
5.3.200.0000.02313.77
5.3.190.0070.02313.77
5.3.180.0020.02213.77
5.3.170.0000.02113.77
5.3.160.0000.02313.77
5.3.150.0060.03013.77
5.3.140.0030.01813.77
5.3.130.0020.02113.77
5.3.120.0050.02013.77
5.3.110.0070.01713.77
5.3.100.0030.01813.77
5.3.90.0030.01813.77
5.3.80.0000.02013.77
5.3.70.0020.01813.77
5.3.60.0010.02113.77
5.3.50.0030.01613.77
5.3.40.0030.01813.77
5.3.30.0000.02113.77
5.3.20.0010.02313.77
5.3.10.0020.01813.77
5.3.00.0000.02013.77

preferences:
36.34 ms | 401 KiB | 5 Q