3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rules = [ '1' => '1.2', '5-10' => '6.25', '10-15' => '9.2', '15-20' => '10.9', ]; function costFromWeight($weight, array $newRules): array { $parsed = []; foreach ($newRules as $range => $cost) { if (sscanf($range, '%d-%d', $min, $max) === 1) { $default = [$min, $min, (float) $cost]; } else { $parsed[] = [$min, $max, (float) $cost]; } } $result = ['cost' => 0]; while ($weight > 0) { foreach ($parsed as $i => [$min, $max, $cost]) { if ($weight <= $max) { if (!$i && $weight <= $min) { [$min, $max, $cost] = $default; } break; } } $result[$max] = ($result[$max] ?? 0) + 1; $result['cost'] += $cost; $weight -= $max; } return $result; } foreach ([49, 47.75, 38, 35, 23, 15, 14, 10.5, 4] as $weight) { echo "$weight :: "; print_r(costFromWeight($weight, $rules)); echo "\n---\n"; }

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.120.0140.00719.41
8.4.110.0050.00423.91
8.4.100.0080.00417.81
8.4.90.0040.00620.80
8.4.80.0050.00420.71
8.4.70.0100.00920.58
8.4.60.0090.01120.43
8.4.50.0130.00722.38
8.4.40.0160.00418.69
8.4.30.0160.00318.68
8.4.20.0070.01119.72
8.4.10.0080.00019.63
8.3.250.0100.01016.48
8.3.240.0120.00716.54
8.3.230.0150.00416.55
8.3.220.0080.00919.09
8.3.210.0120.00316.34
8.3.200.0070.00216.61
8.3.190.0070.00217.20
8.3.180.0120.01019.02
8.3.170.0000.02018.90
8.3.160.0070.01118.46
8.3.150.0130.00716.56
8.3.140.0070.00316.62
8.3.130.0040.00418.32
8.3.120.0060.00319.00
8.3.110.0000.01020.94
8.3.100.0030.00718.39
8.3.90.0090.00926.77
8.3.80.0080.00418.56
8.3.70.0040.01118.43
8.3.60.0120.00416.50
8.3.50.0100.00718.53
8.3.40.0280.01117.38
8.3.30.0290.00717.50
8.3.20.0230.01117.13
8.3.10.0190.01317.50
8.3.00.0270.00317.13
8.2.290.0120.00716.83
8.2.280.0020.00720.07
8.2.270.0070.01016.51
8.2.260.0060.00316.96
8.2.250.0100.00618.48
8.2.240.0040.00419.08
8.2.230.0100.00722.58
8.2.220.0070.01124.06
8.2.210.0040.00426.77
8.2.200.0080.01116.63
8.2.190.0090.00616.63
8.2.180.0080.00816.63
8.2.170.0230.01217.63
8.2.160.0250.01117.38
8.2.150.0210.01217.50
8.2.140.0270.00717.00
8.2.130.0290.00517.37
8.2.120.0300.00917.38
8.2.110.0270.00717.50
8.2.100.0250.00917.47
8.2.90.0290.00717.38
8.2.80.0210.01217.34
8.2.70.0280.01017.50
8.2.60.0190.01317.25
8.2.50.0340.00017.00
8.2.40.0100.02117.38
8.2.30.0220.00917.63
8.2.20.0110.00617.63
8.2.10.0260.00417.63
8.2.00.0210.01017.21
8.1.330.0090.01016.21
8.1.320.0130.00616.26
8.1.310.0030.00518.69
8.1.300.0000.00818.57
8.1.290.0050.00530.84
8.1.280.0130.00516.38
8.1.270.0100.01317.25
8.1.260.0260.00717.24
8.1.250.0260.01117.13
8.1.240.0300.00316.96
8.1.230.0260.00717.38
8.1.220.0290.00717.13
8.1.210.0290.00317.13
8.1.200.0210.01417.00
8.1.190.0190.01517.13
8.1.180.0290.01317.11
8.1.170.0330.00617.10
8.1.160.0230.01317.13
8.1.150.0260.00317.13
8.1.140.0190.01117.13
8.1.130.0210.01017.25
8.1.120.0220.01117.10
8.1.110.0220.00917.13
8.1.100.0280.00617.25
8.1.90.0260.00716.98
8.1.80.0230.01217.00
8.1.70.0190.01317.35
8.1.60.0270.00517.13
8.1.50.0240.00917.35
8.1.40.0220.01117.13
8.1.30.0200.01316.88
8.1.20.0260.00917.25
8.1.10.0240.01317.50
8.1.00.0210.01017.25

preferences:
26.71 ms | 403 KiB | 5 Q