3v4l.org

run code in 300+ PHP versions simultaneously
<?php $max = 111; //265; $items = [50, 45, 30, 60, 70, 80]; function nextFitDecreasing(array $items, int $max): array { rsort($items); $result = []; foreach ($items as $item) { if (!isset($pallet) || (array_sum($pallet) + $item) > $max) { unset($pallet); $result[] = &$pallet; } $pallet[] = $item; } return $result; } function firstFitDecreasing(array $items, int $max): array { rsort($items); $result = []; foreach ($items as $item) { foreach ($result as &$pallet) { if (array_sum($pallet) + $item <= $max) { $pallet[] = $item; continue 2; } } $result[] = [$item]; } return $result; } var_export(nextFitDecreasing($items, $max)); echo "\n---\n"; var_export(firstFitDecreasing($items, $max));

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.4.130.0140.00718.61
8.4.120.0040.00620.54
8.4.110.0120.00920.68
8.4.100.0080.00417.79
8.4.90.0160.00517.71
8.4.80.0070.00218.11
8.4.70.0060.00817.82
8.4.60.0040.00717.67
8.4.50.0140.00819.65
8.4.40.0130.00720.52
8.4.30.0130.00318.79
8.4.20.0030.01625.81
8.4.10.0080.00322.20
8.3.260.0120.00716.74
8.3.250.0110.00816.98
8.3.240.0110.00816.46
8.3.230.0070.01116.55
8.3.220.0100.00817.20
8.3.210.0080.01016.48
8.3.200.0110.00816.84
8.3.190.0040.00417.14
8.3.180.0090.00916.69
8.3.170.0090.00019.16
8.3.160.0110.00716.56
8.3.150.0150.00420.73
8.3.140.0040.00417.36
8.3.130.0160.00318.36
8.3.120.0060.00320.61
8.3.110.0000.00918.43
8.3.100.0130.00718.47
8.3.90.0040.00426.77
8.3.80.0040.00417.97
8.3.70.0080.00818.43
8.3.60.0070.01118.56
8.3.50.0090.01316.62
8.3.40.0070.01120.52
8.3.30.0110.00418.89
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0090.00026.16
8.2.290.0100.00920.62
8.2.280.0100.00618.76
8.2.270.0090.01216.78
8.2.260.0040.00418.81
8.2.250.0040.00418.49
8.2.240.0030.01216.99
8.2.230.0090.00020.94
8.2.220.0090.00024.06
8.2.210.0040.01426.77
8.2.200.0040.00416.88
8.2.190.0120.00616.58
8.2.180.0060.00816.61
8.2.170.0110.00319.00
8.2.160.0140.00022.96
8.2.150.0070.00025.66
8.2.140.0070.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00720.80
8.2.110.0060.00319.33
8.2.100.0060.00617.79
8.2.90.0000.00819.29
8.2.80.0000.00817.63
8.2.70.0050.00317.63
8.2.60.0030.00617.93
8.2.50.0060.00318.07
8.2.40.0040.00420.97
8.2.30.0000.00817.96
8.2.20.0040.00419.27
8.2.10.0080.00018.00
8.2.00.0030.00519.42
8.1.330.0150.00721.90
8.1.320.0120.00916.20
8.1.310.0080.00017.00
8.1.300.0090.00018.06
8.1.290.0070.00430.84
8.1.280.0110.00725.92
8.1.270.0000.00824.66
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0040.00422.23
8.1.230.0110.00020.84
8.1.220.0000.00817.74
8.1.210.0040.00418.97
8.1.200.0060.00317.36
8.1.190.0030.00617.23
8.1.180.0000.00818.10
8.1.170.0000.00818.59
8.1.160.0070.00018.84
8.1.150.0070.00018.58
8.1.140.0030.00517.41
8.1.130.0060.00319.25
8.1.120.0050.00319.24
8.1.110.0080.00019.29
8.1.100.0050.00319.25
8.1.90.0090.00019.34
8.1.80.0000.00819.29
8.1.70.0060.00319.30
8.1.60.0050.00319.43
8.1.50.0060.00319.40
8.1.40.0000.00819.33
8.1.30.0000.00819.36
8.1.20.0050.00319.34
8.1.10.0000.00719.36
8.1.00.0040.00419.43
8.0.300.0040.00420.21
8.0.290.0040.00416.75
8.0.280.0000.00718.38
8.0.270.0030.00318.08
8.0.260.0040.00418.63
8.0.250.0040.00418.57
8.0.240.0040.00418.54
8.0.230.0040.00418.53
8.0.220.0040.00418.60
8.0.210.0000.00718.61
8.0.200.0040.00418.66
8.0.190.0070.00018.54
8.0.180.0040.00418.62
8.0.170.0070.00018.62
8.0.160.0040.00418.71
8.0.150.0000.00718.51
8.0.140.0050.00218.59
8.0.130.0000.00718.51
8.0.120.0000.00718.63
8.0.110.0040.00418.64
8.0.100.0040.00418.68
8.0.90.0040.00418.53
8.0.80.0040.00418.53
8.0.70.0040.00418.47
8.0.60.0030.00618.52
8.0.50.0080.00018.63
8.0.30.0040.00418.54
8.0.20.0060.00318.57
8.0.10.0060.00318.77

preferences:
29.44 ms | 403 KiB | 5 Q