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 = [ 'Cala', 'Ocean', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0.02, 3, 0.02); $ratingCoefOptions = range(10, 10000, 10); 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.0130.17918.31
8.3.50.0080.18921.21
8.3.40.0170.19818.91
8.3.30.0100.18420.42
8.3.20.0100.09520.74
8.3.10.0070.09921.34
8.3.00.0070.08922.69
8.2.180.0070.18916.63
8.2.170.0100.18022.96
8.2.160.0070.18620.52
8.2.150.0070.09224.18
8.2.140.0140.08824.66
8.2.130.0100.09026.16
8.2.120.0000.09721.17
8.2.110.0100.17522.37
8.2.100.0200.13317.97
8.2.90.0100.14719.30
8.2.80.0000.15318.18
8.2.70.0070.14517.75
8.2.60.0070.14518.05
8.2.50.0030.14518.07
8.2.40.0030.15318.53
8.2.30.0100.13519.70
8.2.20.0030.15318.07
8.2.10.0070.14217.95
8.2.00.0030.14417.94
8.1.280.0270.19625.92
8.1.270.0110.09623.99
8.1.260.0170.11426.35
8.1.250.0030.09528.09
8.1.240.0070.18820.83
8.1.230.0200.12821.08
8.1.220.0070.14618.77
8.1.210.0030.13819.01
8.1.200.0030.15417.73
8.1.190.0030.14417.77
8.1.180.0000.14518.10
8.1.170.0100.13218.97
8.1.160.0000.15419.27
8.1.150.0030.14518.82
8.1.140.0030.15117.77
8.1.130.0030.13518.14
8.1.120.0000.15117.67
8.1.110.0030.14317.71
8.1.100.0000.15817.80
8.1.90.0030.14817.79
8.1.80.0030.13917.72
8.1.70.0000.14817.67
8.1.60.0030.18617.95
8.1.50.0070.18217.75
8.1.40.0000.20017.86
8.1.30.0100.17717.84
8.1.20.0100.18117.95
8.1.10.0070.17717.93
8.1.00.0070.18217.79
8.0.300.0100.13820.18
8.0.290.0030.14317.43
8.0.280.0130.13818.68
8.0.270.0030.14717.43
8.0.260.0000.14716.98
8.0.250.0030.14317.01
8.0.240.0070.14917.05
8.0.230.0030.15117.00
8.0.220.0000.14917.05
8.0.210.0070.14216.98
8.0.200.0070.14317.13
8.0.190.0030.18417.02
8.0.180.0030.18817.13
8.0.170.0030.18517.13
8.0.160.0060.18316.92
8.0.150.0060.17716.98
8.0.140.0070.18817.01
8.0.130.0030.17913.57
8.0.120.0000.18917.01
8.0.110.0070.18216.91
8.0.100.0070.18017.04
8.0.90.0000.19017.11
8.0.80.0060.25616.96
8.0.70.0030.18616.99
8.0.60.0070.18516.88
8.0.50.0070.17817.04
8.0.30.0130.26017.39
8.0.20.0250.28517.40
8.0.10.0070.18317.01
8.0.00.0300.26416.74
7.4.330.0000.13816.95
7.4.320.0000.14816.52
7.4.300.0030.14616.73
7.4.290.0030.18116.61
7.4.280.0030.17916.60
7.4.270.0100.17816.73
7.4.260.0000.18413.52
7.4.250.0070.17716.51
7.4.240.0030.18416.62
7.4.230.0000.18416.81
7.4.220.0260.28116.80
7.4.210.0130.26416.76
7.4.200.0030.18516.51
7.4.190.0000.18716.88
7.4.160.0200.25016.51
7.4.150.0100.26817.40
7.4.140.0320.30417.86
7.4.130.0100.26016.65
7.4.120.0300.32016.75
7.4.110.0270.24116.84
7.4.100.0290.25416.61
7.4.90.0230.24716.58
7.4.80.0290.28519.39
7.4.70.0030.25416.55
7.4.60.0310.37716.59
7.4.50.0100.15116.61
7.4.40.0100.26822.77
7.4.30.0230.40416.51
7.4.00.0130.26815.54
7.3.330.0100.16813.73
7.3.320.0000.18213.65
7.3.310.0030.18016.65
7.3.300.0030.20216.40
7.3.290.0030.24616.53
7.3.280.0090.31816.57
7.3.270.0350.26317.40
7.3.260.0330.33018.24
7.3.250.0170.32516.74
7.3.240.0200.26116.82
7.3.230.0100.25716.57
7.3.210.0420.34816.48
7.3.200.0160.35819.39
7.3.190.0320.36316.67
7.3.180.0160.26216.50
7.3.170.0130.29216.45
7.3.160.0320.43916.53
7.3.120.0070.29515.17
7.2.330.0270.26316.79
7.2.320.0230.29916.74
7.2.310.0200.29417.01
7.2.300.0200.26316.99
7.2.290.0250.31016.96
7.2.110.0070.21116.94
7.2.60.0030.15817.39
7.2.00.0030.18719.62
7.1.200.0100.17816.06
7.1.100.0030.20618.46
7.1.70.0160.22717.29
7.1.60.0490.19119.17
7.1.50.0100.18417.51
7.0.200.1130.21917.23

preferences:
39.1 ms | 401 KiB | 5 Q