3v4l.org

run code in 300+ PHP versions simultaneously
<?php function optimalChange(int $amount, array $denominations): ?array { if (!$amount) { return []; // happy ending } foreach ($denominations as $d) { if ($d <= $amount) { $deeper = optimalChange($amount - $d, $denominations); if ($deeper !== null) { $result = array_merge([$d], $deeper); break; // run up the recursive branch } } } return $result ?? null; } $target = 23; $denominations = [10, 5, 2]; // must be rsort()ed at declaration foreach (range(0, 35) as $target) { printf( "%s: %s\n", $target, json_encode( optimalChange($target, $denominations) ?: 'Sorry' ) ); }

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.20.0090.01017.70
8.5.10.0130.00718.39
8.5.00.0130.01119.90
8.4.160.0140.00723.95
8.4.150.0020.00114.05
8.4.140.0120.00917.48
8.4.130.0060.00217.95
8.4.120.0100.00920.72
8.4.110.0110.00918.71
8.4.100.0140.00717.77
8.4.90.0100.00918.70
8.4.80.0140.00818.10
8.4.70.0130.00717.71
8.4.60.0130.00819.32
8.4.50.0140.00619.60
8.4.40.0130.00617.87
8.4.30.0150.00618.54
8.4.20.0100.01017.73
8.4.10.0070.01419.50
8.3.290.0120.01220.79
8.3.280.0100.00918.29
8.3.270.0140.00516.45
8.3.260.0130.00716.73
8.3.250.0130.00718.87
8.3.240.0120.00716.54
8.3.230.0120.00616.77
8.3.220.0040.00517.05
8.3.210.0110.00716.61
8.3.200.0110.00716.45
8.3.190.0100.00916.40
8.3.180.0150.00516.54
8.3.170.0030.01718.73
8.3.160.0120.00618.19
8.3.150.0190.00016.42
8.3.140.0040.01116.72
8.3.130.0000.00816.51
8.3.120.0030.00719.04
8.3.110.0060.00320.94
8.3.100.0000.00818.22
8.3.90.0080.00026.77
8.3.80.0050.00517.97
8.3.70.0110.00418.43
8.3.60.0150.00618.40
8.3.50.0110.01116.64
8.3.40.0100.00319.91
8.3.30.0030.01221.59
8.3.20.0080.00024.18
8.3.10.0040.00424.66
8.3.00.0070.01426.35
8.2.300.0120.00822.29
8.2.290.0050.00420.51
8.2.280.0120.00620.10
8.2.270.0090.00317.41
8.2.260.0070.01118.29
8.2.250.0140.00318.42
8.2.240.0090.00018.88
8.2.230.0030.00622.58
8.2.220.0070.00324.06
8.2.210.0050.00526.77
8.2.200.0040.00418.16
8.2.190.0150.00316.58
8.2.180.0180.00416.63
8.2.170.0080.00819.09
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0070.00324.66
8.2.130.0110.00726.35
8.2.120.0070.01326.35
8.2.110.0090.00926.35
8.2.100.0120.00626.35
8.2.90.0150.00726.35
8.2.80.0060.01226.35
8.2.70.0100.00626.35
8.2.60.0060.01026.35
8.2.50.0100.00726.35
8.2.40.0100.00626.35
8.2.30.0070.00726.35
8.2.20.0040.01126.35
8.2.10.0060.00326.35
8.2.00.0050.00326.35
8.1.340.0090.01221.69
8.1.330.0090.01020.49
8.1.320.0100.00916.12
8.1.310.0060.00318.53
8.1.300.0150.00317.90
8.1.290.0090.00330.84
8.1.280.0110.00425.92
8.1.270.0070.00020.37
8.1.260.0030.00526.35
8.1.250.0150.00026.35
8.1.240.0060.00326.35
8.1.230.0040.00426.35
8.1.220.0030.00626.35
8.1.210.0080.00026.35
8.1.200.0000.00826.35
8.1.190.0080.00026.35
8.1.180.0040.00426.35
8.1.170.0040.00426.35
8.1.160.0040.00426.35
8.1.150.0080.00026.35
8.1.140.0030.00526.35
8.1.130.0050.00326.35
8.1.120.0090.00026.35
8.1.110.0080.00026.35
8.1.100.0040.00426.35
8.1.90.0060.00326.35
8.1.80.0090.00026.35
8.1.70.0080.00026.35
8.1.60.0040.00426.35
8.1.50.0040.00426.35
8.1.40.0080.00026.35
8.1.30.0040.00426.35
8.1.20.0080.00026.35
8.1.10.0060.00326.35
8.1.00.0050.00326.35

preferences:
35.28 ms | 403 KiB | 5 Q