3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => 50, 1 => 200, 2 => 75, 3 => 150, 4 => 100, 5 => 125, 6 => 150, 7 => 300, 8 => 300, 9 => 300, 10 => 300, 11 => 300, 12 => 300, 13 => 300, 14 => 300, 15 => 300, ]; function consolidate(array $array, int $capacity = 500): array { arsort($array); $bins = [[]]; foreach ($array as $value) { $added = false; foreach ($bins as &$bin) { if ($capacity >= (array_sum($bin) + $value)) { $bin[] = $value; $added = true; continue 2; } } if (!$added) { $bins[] = [$value]; } } return array_map('array_sum', array_filter($bins)); } var_export(consolidate($array));

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.0040.01118.42
8.3.50.0130.00318.57
8.3.40.0070.00720.34
8.3.30.0100.00320.91
8.3.20.0070.00024.18
8.3.10.0050.00224.66
8.3.00.0070.00026.16
8.2.180.0140.00718.16
8.2.170.0090.00618.99
8.2.160.0030.01022.96
8.2.150.0030.00625.66
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00419.48
8.2.110.0070.00421.08
8.2.100.0080.00417.91
8.2.90.0000.00718.22
8.2.80.0060.00320.01
8.2.70.0030.00617.50
8.2.60.0130.00517.38
8.2.50.0100.00717.21
8.2.40.0110.00617.50
8.2.30.0140.00317.25
8.2.20.0090.00917.50
8.2.10.0170.00017.38
8.2.00.0120.00417.25
8.1.280.0090.00925.92
8.1.270.0080.00024.66
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0080.00023.97
8.1.230.0030.00720.97
8.1.220.0080.00017.80
8.1.210.0000.00918.77
8.1.200.0090.00017.47
8.1.190.0100.00717.00
8.1.180.0050.01116.98
8.1.170.0110.00616.97
8.1.160.0060.01117.00
8.1.150.0080.01117.00
8.1.140.0100.00617.25
8.1.130.0100.00617.13
8.1.120.0110.00717.50
8.1.110.0120.00617.13
8.1.100.0090.00917.50
8.1.90.0080.00817.13
8.1.80.0100.00717.13
8.1.70.0150.00317.38
8.1.60.0100.00817.23
8.1.50.0100.01017.12
8.1.40.0160.00317.25
8.1.30.0140.00517.25
8.1.20.0140.00517.38
8.1.10.0120.00917.50
8.1.00.0050.01517.13
8.0.300.0040.00420.03
8.0.290.0040.00416.75
8.0.280.0110.00816.73
8.0.270.0160.00316.63
8.0.260.0110.00616.52
8.0.250.0160.00016.75
8.0.240.0120.00416.74
8.0.230.0170.00016.63
8.0.220.0070.00716.52
8.0.210.0140.00316.75
8.0.200.0160.00316.75
8.0.190.0100.00716.52
8.0.180.0100.00716.52
8.0.170.0150.00016.52
8.0.160.0120.00216.52
8.0.150.0140.00016.52
8.0.140.0070.00716.52
8.0.130.0100.00316.52
8.0.120.0050.00916.52
8.0.110.0120.00316.52
8.0.100.0110.00416.52
8.0.90.0150.00016.52
8.0.80.0140.00016.52
8.0.70.0100.00516.52
8.0.60.0140.00016.52
8.0.50.0160.00016.52
8.0.30.0120.00016.52
8.0.20.0150.00016.73
8.0.10.0130.00316.52

preferences:
36.3 ms | 400 KiB | 5 Q