3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight_distribution = [ '1' => 0, '2-5' => 0, '5-10' => 6, '10-15' => 7, '15-20' => 3, ]; function distribute_weights(int|float $weight, array &$distribution): void { $parsed = []; foreach ($distribution as $range => $cost) { if (sscanf($range, '%d-%d', $min, $max) === 1) { $default = [$min, $min]; } else { $parsed[] = [$min, $max]; } } while ($weight > 0) { foreach ($parsed as $i => [$min, $max]) { if ($weight <= $max) { if (!$i && $weight <= $min) { [$min, $max] = $default; } break; } } if ($min === $max) { ++$distribution[$max]; } else { ++$distribution[$min . '-' . $max]; } $weight -= $max; } } distribute_weights(21, $weight_distribution); print_r($weight_distribution);

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.5.10.0090.00916.48
8.5.00.0150.00720.04
8.4.160.0170.00523.81
8.4.150.0030.00014.05
8.4.140.0130.01117.26
8.4.130.0120.00817.70
8.4.120.0140.00520.60
8.4.110.0130.00722.31
8.4.100.0140.00717.77
8.4.90.0060.00318.02
8.4.80.0040.00517.70
8.4.70.0090.01217.77
8.4.60.0060.00618.78
8.4.50.0090.01317.60
8.4.40.0120.00318.71
8.4.30.0040.01220.80
8.4.20.0070.01419.61
8.4.10.0090.00019.42
8.3.280.0140.00618.53
8.3.270.0110.00916.38
8.3.260.0110.00616.43
8.3.250.0080.01119.03
8.3.240.0130.00716.55
8.3.230.0120.00716.64
8.3.220.0090.00917.34
8.3.210.0090.01016.85
8.3.200.0140.00416.75
8.3.190.0110.00717.17
8.3.180.0130.00716.49
8.3.170.0110.00722.98
8.3.160.0070.01118.95
8.3.150.0040.01617.16
8.3.140.0060.00317.30
8.3.130.0070.01316.59
8.3.120.0000.00920.86
8.3.110.0040.00420.94
8.3.100.0000.00924.06
8.3.90.0050.00326.77
8.3.80.0040.00717.97
8.3.70.0130.01016.63
8.3.60.0100.01325.92
8.3.50.0110.01125.92
8.3.40.0360.01425.92
8.3.30.0410.00725.92
8.3.20.0300.01425.92
8.3.10.0340.01025.92
8.3.00.0370.00725.92
8.2.290.0080.01220.45
8.2.280.0070.00218.44
8.2.270.0180.00019.04
8.2.260.0070.00716.95
8.2.250.0040.01116.39
8.2.240.0120.00619.08
8.2.230.0120.00622.58
8.2.220.0060.00337.54
8.2.210.0000.00826.77
8.2.200.0000.00918.29
8.2.190.0110.00416.58
8.2.180.0330.01225.92
8.2.170.0400.01325.92
8.2.160.0350.00725.92
8.2.150.0280.01425.92
8.2.140.0390.01825.92
8.2.130.0400.01125.92
8.2.120.0300.00825.92
8.2.110.0290.01125.92
8.2.100.0240.01225.92
8.2.90.0280.01225.92
8.2.80.0390.00825.92
8.2.70.0410.00425.92
8.2.60.0410.01025.92
8.2.50.0160.01625.92
8.2.40.0330.00725.92
8.2.30.0240.00925.92
8.2.20.0260.00625.92
8.2.10.0280.00725.92
8.2.00.0160.01625.92
8.1.330.0140.00522.07
8.1.320.0100.00916.31
8.1.310.0040.00417.80
8.1.300.0040.00420.20
8.1.290.0090.00030.84
8.1.280.0340.00925.92
8.1.270.0430.01025.92
8.1.260.0320.01025.92
8.1.250.0410.01425.92
8.1.240.0370.01125.92
8.1.230.0400.00725.92
8.1.220.0380.01025.92
8.1.210.0360.00825.92
8.1.200.0320.01425.92
8.1.190.0330.00725.92
8.1.180.0260.01725.92
8.1.170.0330.01025.92
8.1.160.0360.00925.92
8.1.150.0360.01025.92
8.1.140.0370.00725.92
8.1.130.0300.01625.92
8.1.120.0410.00325.92
8.1.110.0340.01025.92
8.1.100.0500.00725.92
8.1.90.0310.00425.92
8.1.80.0210.01125.92
8.1.70.0310.00825.92
8.1.60.0400.00825.92
8.1.50.0380.01025.92
8.1.40.0440.00725.92
8.1.30.0570.00325.92
8.1.20.0400.00725.92
8.1.10.0360.00725.92
8.1.00.0300.01525.92

preferences:
41.94 ms | 403 KiB | 5 Q