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, 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.40.0100.22918.96
8.3.30.0100.23820.46
8.3.20.0100.10220.61
8.3.10.0070.10321.31
8.3.00.0030.10523.91
8.2.170.0130.19522.96
8.2.160.0030.20520.47
8.2.150.0070.10024.18
8.2.140.0070.10224.66
8.2.130.0130.09426.16
8.2.120.0070.10221.18
8.2.110.0100.20119.52
8.2.100.0100.16518.16
8.2.90.0030.17819.30
8.2.80.0030.16918.18
8.2.70.0070.17017.63
8.2.60.0130.16218.05
8.2.50.0000.17418.07
8.2.40.0000.16718.41
8.2.30.0100.15019.60
8.2.20.0000.16717.93
8.2.10.0030.16917.89
8.2.00.0070.16417.93
8.1.270.0100.09523.99
8.1.260.0070.09826.35
8.1.250.0100.09528.09
8.1.240.0130.20620.97
8.1.230.0100.15221.18
8.1.220.0000.17618.77
8.1.210.0000.19018.99
8.1.200.0030.16817.60
8.1.190.0070.16417.78
8.1.180.0030.17218.10
8.1.170.0100.15218.79
8.1.160.0030.17119.16
8.1.150.0070.16918.77
8.1.140.0030.16517.66
8.1.130.0030.15918.00
8.1.120.0030.16717.67
8.1.110.0000.16817.70
8.1.100.0000.18117.65
8.1.90.0030.16717.70
8.1.80.0000.16617.68
8.1.70.0030.17017.57
8.1.60.0030.21317.69
8.1.50.0030.21017.59
8.1.40.0000.21517.71
8.1.30.0000.21417.73
8.1.20.0070.20917.83
8.1.10.0070.20617.80
8.1.00.0030.21417.69
8.0.300.0000.16620.16
8.0.290.0030.16917.43
8.0.280.0000.16818.64
8.0.270.0030.16817.41
8.0.260.0030.16518.62
8.0.250.0100.16017.04
8.0.240.0070.16317.21
8.0.230.0070.16517.07
8.0.220.0000.17017.13
8.0.210.0030.16517.09
8.0.200.0070.16617.22
8.0.190.0070.20517.12
8.0.180.0070.20717.15
8.0.170.0030.21217.14
8.0.160.0000.21317.09
8.0.150.0000.21117.12
8.0.140.0070.24016.97
8.0.130.0070.21013.56
8.0.120.0100.21316.94
8.0.110.0070.20517.05
8.0.100.0070.20517.17
8.0.90.0030.21116.91
8.0.80.0100.29017.15
8.0.70.0070.21017.11
8.0.60.0030.21217.06
8.0.50.0070.20817.00
8.0.30.0080.32017.27
8.0.20.0110.33617.40
8.0.10.0030.20917.21
8.0.00.0160.29917.11
7.4.330.0070.15216.87
7.4.320.0000.17116.71
7.4.300.0030.16316.68
7.4.290.0070.20216.61
7.4.280.0030.21016.72
7.4.270.0030.20516.58
7.4.260.0070.20513.56
7.4.250.0030.21116.68
7.4.240.0030.20616.81
7.4.230.0030.22016.89
7.4.220.0030.30716.75
7.4.210.0110.28216.76
7.4.200.0070.20516.90
7.4.190.0070.21016.98
7.4.160.0230.32516.72
7.4.150.0130.26817.40
7.4.140.0130.26817.86
7.4.130.0130.31416.90
7.4.120.0160.29716.79
7.4.110.0230.31516.86
7.4.100.0060.35316.65
7.4.90.0170.39016.77
7.4.80.0000.34319.39
7.4.70.0230.28216.65
7.4.60.0070.30616.70
7.4.50.0070.17116.60
7.4.40.0500.27222.77
7.4.30.0220.26516.66
7.3.330.0000.20613.64
7.3.320.0000.22413.63
7.3.310.0030.20316.60
7.3.300.0070.20016.51
7.3.290.0030.27916.65
7.3.280.0200.32416.59
7.3.270.0190.28417.40
7.3.260.0230.39018.24
7.3.250.0130.28416.71
7.3.240.0190.27116.98
7.3.230.0160.27516.91
7.3.210.0250.37117.00
7.3.200.0150.48619.39
7.3.190.0100.42016.88
7.3.180.0210.28416.54
7.3.170.0170.31816.90
7.3.160.0160.26016.70
7.2.330.0100.29717.11
7.2.320.0210.41216.76
7.2.310.0190.34816.84
7.2.300.0130.31016.82
7.2.290.0190.29017.07
7.2.90.0330.21914.71
7.2.80.0030.36314.71
7.2.70.0700.27715.12
7.2.60.0290.26915.05
7.2.50.0260.33314.87
7.2.40.0560.37015.13
7.2.30.0380.32915.25
7.2.20.0140.30415.33
7.2.10.0930.26115.24
7.2.00.0160.26515.16
7.1.210.1170.29413.81
7.1.200.0130.28813.80
7.1.190.0190.28514.00
7.1.180.0120.35513.89
7.1.170.1460.43313.84
7.1.160.0310.38813.84
7.1.150.1420.33014.39
7.1.140.0190.34713.84
7.1.130.0340.35514.08
7.1.120.0070.37514.27
7.1.110.0430.38114.24
7.1.100.0300.32314.12
7.1.90.1220.31414.11
7.1.80.0480.32413.96
7.1.70.0760.32713.70
7.1.60.0290.31031.86
7.1.50.0310.30732.12
7.1.40.1010.29732.11
7.1.30.0270.38631.98
7.1.20.0910.28131.88
7.1.10.0830.32314.06
7.1.00.0330.32513.48
7.0.310.0120.42413.52
7.0.300.1760.49313.49
7.0.290.0870.41313.63
7.0.280.0370.45513.57
7.0.270.0280.31213.72
7.0.260.0100.42713.70
7.0.250.0420.50913.63
7.0.240.0230.31413.67
7.0.230.0230.38213.73
7.0.220.0280.48713.68
7.0.210.0210.37913.50
7.0.200.1080.35013.42
7.0.190.0850.28913.85
7.0.180.0900.31813.77
7.0.170.0880.34113.44
7.0.160.0730.33313.67
7.0.150.0760.31713.57
7.0.140.0660.32513.58
7.0.130.0850.43813.78
7.0.120.0820.34013.69
7.0.110.0070.33713.75
7.0.100.0860.34013.94
7.0.90.1000.42813.65
7.0.80.0780.38213.89
7.0.70.0980.32813.61
7.0.60.1030.34513.82
7.0.50.0250.37013.72
7.0.40.0340.42813.53
7.0.30.0350.37113.67
7.0.20.0520.31613.84
7.0.10.0940.34213.73
7.0.00.0110.38613.73
5.6.300.0290.80114.84
5.6.290.0130.84114.68
5.6.280.0440.79714.55
5.6.270.0141.09114.83
5.6.260.0190.80914.46
5.6.250.0181.02414.58
5.6.240.0220.91714.68
5.6.230.0130.79114.51
5.6.220.0150.78414.74
5.6.210.0330.96114.66
5.6.200.0220.76014.46
5.6.190.0160.80114.59
5.6.180.0140.79114.68
5.6.170.0120.75014.45
5.6.160.0210.77214.50
5.6.150.0090.82014.38
5.6.140.0220.75214.39
5.6.130.0280.75614.57
5.6.120.0420.78314.36
5.6.110.0240.77914.57
5.6.100.0100.72514.64
5.5.380.0160.78211.41
5.5.370.0100.83311.42
5.5.360.0130.78611.42
5.5.350.0060.77111.47
5.5.340.0280.85411.26
5.5.330.0220.82111.02
5.5.320.0340.96011.48
5.5.310.0390.82511.31
5.5.300.0160.84611.24
5.5.290.0080.90611.55
5.5.280.0150.92411.78
5.5.270.0160.92611.38
5.5.260.0310.72911.63
5.4.450.0191.01411.51
5.4.440.0320.84011.55
5.4.430.0070.87711.17

preferences:
45.16 ms | 400 KiB | 5 Q