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', 'Ya', 'Ocean', ]; for ( $i=0; $i<count($hotels); $i++ ) { $hotels[$i][4] = 0; } $starCoefOptions = range(0, 5, 0.1); $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.0160.01918.68
8.3.50.0180.01621.33
8.3.40.0210.02718.93
8.3.30.0200.01720.42
8.3.20.0140.02420.34
8.3.10.0070.01421.33
8.3.00.0060.01522.55
8.2.180.0260.01916.62
8.2.170.0380.02422.96
8.2.160.0310.01022.38
8.2.150.0150.00824.18
8.2.140.0070.00724.66
8.2.130.0180.00326.16
8.2.120.0030.01021.12
8.2.110.0220.01420.72
8.2.100.0270.00817.87
8.2.90.0060.01619.33
8.2.80.0070.01618.17
8.2.70.0030.02417.75
8.2.60.0060.01618.05
8.2.50.0070.01618.07
8.2.40.0030.01718.46
8.2.30.0060.01619.73
8.2.20.0080.00517.89
8.2.10.0080.00818.04
8.2.00.0070.01617.95
8.1.280.0170.02425.92
8.1.270.0070.01023.99
8.1.260.0160.00626.35
8.1.250.0100.01028.09
8.1.240.0100.01622.20
8.1.230.0130.01322.44
8.1.220.0060.01618.77
8.1.210.0000.02119.32
8.1.200.0130.01317.48
8.1.190.0000.01417.78
8.1.180.0130.00718.10
8.1.170.0130.01018.86
8.1.160.0060.01619.25
8.1.150.0070.01418.94
8.1.140.0060.01717.85
8.1.130.0030.01018.07
8.1.120.0030.01317.66
8.1.110.0000.01317.77
8.1.100.0070.00717.75
8.1.90.0070.00717.74
8.1.80.0040.01217.74
8.1.70.0070.00717.73
8.1.60.0030.01217.78
8.1.50.0000.01417.72
8.1.40.0090.00917.68
8.1.30.0080.01117.92
8.1.20.0070.01717.79
8.1.10.0070.00717.87
8.1.00.0030.01217.68
8.0.300.0070.01720.27
8.0.290.0070.01317.30
8.0.280.0090.01318.49
8.0.270.0040.01117.48
8.0.260.0000.02117.06
8.0.250.0000.01317.13
8.0.240.0130.01317.13
8.0.230.0000.01516.95
8.0.220.0070.01417.11
8.0.210.0070.01617.08
8.0.200.0100.01017.06
8.0.190.0030.01117.13
8.0.180.0070.00717.10
8.0.170.0040.01217.08
8.0.160.0060.00617.00
8.0.150.0030.01017.02
8.0.140.0170.00316.89
8.0.130.0030.01213.51
8.0.120.0040.01117.03
8.0.110.0140.01416.96
8.0.100.0030.01017.01
8.0.90.0070.01416.84
8.0.80.0100.03817.02
8.0.70.0110.00416.86
8.0.60.0060.01916.91
8.0.50.0040.02117.07
8.0.30.0270.04817.00
8.0.20.0340.05417.49
8.0.10.0070.00717.13
8.0.00.0440.03717.02
7.4.330.0080.01016.87
7.4.320.0060.01016.61
7.4.300.0030.01216.73
7.4.290.0070.01516.60
7.4.280.0100.01616.57
7.4.270.0060.01616.62
7.4.260.0060.00913.59
7.4.250.0090.01316.63
7.4.240.0080.00616.56
7.4.230.0100.00716.52
7.4.220.0280.07316.63
7.4.210.0140.03416.69
7.4.200.0000.01616.51
7.4.190.0070.00716.76
7.4.160.0420.03816.67
7.4.150.0350.05917.40
7.4.140.0300.04317.86
7.4.130.0440.03516.70
7.4.120.0400.02916.54
7.4.110.0490.03916.56
7.4.100.0390.03616.71
7.4.90.0300.06016.65
7.4.80.0640.04119.39
7.4.70.0100.02216.85
7.4.60.0220.01016.48
7.4.50.0060.01216.71
7.4.40.0100.01322.77
7.4.30.0230.06416.55
7.3.330.0060.01313.62
7.3.320.0120.01213.66
7.3.310.0060.00916.58
7.3.300.0060.01816.38
7.3.290.0260.04416.48
7.3.280.0200.03616.51
7.3.270.0460.04717.40
7.3.260.0480.03818.24
7.3.250.0360.03716.52
7.3.240.0770.02516.58
7.3.230.0770.06716.75
7.3.210.0430.03816.71
7.3.200.0450.07019.39
7.3.190.0230.06216.77
7.3.180.0170.04116.56
7.3.170.0410.04116.60
7.3.160.0260.03016.48
7.2.330.0420.04317.13
7.2.320.0090.08616.65
7.2.310.0490.11816.65
7.2.300.0180.03716.93
7.2.290.0440.04217.15
5.4.280.0270.09319.57
5.4.270.0230.09019.71
5.4.260.0300.09019.55
5.4.250.0330.09019.48
5.4.240.0370.08019.66
5.4.230.0330.06319.63
5.4.220.0330.08319.56
5.4.210.0370.08019.63
5.4.200.0370.08319.46
5.4.190.0200.10019.70
5.4.180.0130.08319.61
5.4.170.0230.06019.38
5.4.160.0300.08319.71
5.4.150.0200.09719.53
5.4.140.0370.08717.04
5.4.130.0270.08716.93
5.4.120.0430.05016.89
5.4.110.0230.08017.00
5.4.100.0330.06017.00
5.4.90.0200.10017.14
5.4.80.0430.05716.98
5.4.70.0330.08316.95
5.4.60.0230.07317.12
5.4.50.0400.08016.97
5.4.40.0330.08716.89
5.4.30.0270.09716.82
5.4.20.0230.08716.88
5.4.10.0300.06017.05
5.4.00.0270.08716.33
5.3.280.0270.07314.68
5.3.270.0200.05714.59
5.3.260.0270.04714.59
5.3.250.0270.07014.57
5.3.240.0230.04714.44
5.3.230.0200.06014.43
5.3.220.0230.04714.61
5.3.210.0200.07014.44
5.3.200.0230.07014.43
5.3.190.0170.05014.41
5.3.180.0200.06714.61
5.3.170.0130.04314.42
5.3.160.0200.04014.39
5.3.150.0370.03014.47
5.3.140.0230.07314.50
5.3.130.0130.04014.50
5.3.120.0100.04314.50
5.3.110.0270.06714.48
5.3.100.0300.05714.13
5.3.90.0200.04714.10
5.3.80.0230.04714.10
5.3.70.0230.07014.10
5.3.60.0230.05014.10
5.3.50.0270.04714.10
5.3.40.0330.06314.10
5.3.30.0270.04014.10
5.3.20.0230.04014.10
5.3.10.0230.04014.10
5.3.00.0200.05314.10

preferences:
43.29 ms | 401 KiB | 5 Q