3v4l.org

run code in 300+ PHP versions simultaneously
<?php function knapsackLight($value1, $weight1, $value2, $weight2, $maxW) { $result = []; $result[] = ['weight' => $weight1, 'value' => $value1]; $result[] = ['weight' => $weight2, 'value' => $value2]; $result[] = ['weight' => $weight1 + $weight2, 'value' => $value1 + $weight2]; $result = array_filter($result, function($v) use ($maxW) { return $v['weight'] <= $maxW; }); return max(array_column($result, 'value')); } var_dump(knapsackLight(10, 5, 6, 4, 8)); var_dump(knapsackLight(10, 5, 6, 5, 9));

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.0080.00116.66
8.5.00.0110.01320.02
8.4.150.0020.00014.05
8.4.140.0150.00917.75
8.4.130.0070.00417.82
8.4.120.0110.00920.46
8.4.110.0140.00622.33
8.4.100.0130.01018.96
8.4.90.0140.01120.52
8.4.80.0060.00219.07
8.4.70.0120.00818.81
8.4.60.0150.00618.75
8.4.50.0110.00919.28
8.4.40.0040.01522.57
8.4.30.0060.01320.36
8.4.20.0170.00318.89
8.4.10.0160.00317.80
8.3.280.0100.00920.26
8.3.270.0100.00916.28
8.3.260.0110.00816.46
8.3.250.0110.00718.74
8.3.240.0140.00616.51
8.3.230.0120.00816.36
8.3.220.0050.00719.02
8.3.210.0110.00716.61
8.3.200.0080.00116.75
8.3.190.0110.00918.45
8.3.180.0120.00616.52
8.3.170.0190.00016.51
8.3.160.0060.00917.06
8.3.150.0000.01917.27
8.3.140.0060.01220.79
8.3.130.0080.00018.42
8.3.120.0120.00618.89
8.3.110.0080.00020.94
8.3.100.0070.00324.06
8.3.90.0060.00326.77
8.3.80.0090.00016.63
8.3.70.0110.01116.63
8.3.60.0070.01418.43
8.3.50.0100.01017.36
8.3.40.0070.01418.54
8.3.30.0100.00618.84
8.3.20.0060.00320.65
8.3.10.0080.00021.90
8.3.00.0030.00523.61
8.2.290.0030.00419.11
8.2.280.0040.00618.59
8.2.270.0120.00818.70
8.2.260.0110.00716.82
8.2.250.0070.01116.80
8.2.240.0100.00717.11
8.2.230.0080.00422.58
8.2.220.0030.00637.54
8.2.210.0100.00326.77
8.2.200.0030.00616.63
8.2.190.0120.00316.58
8.2.180.0110.00718.16
8.2.170.0130.00322.96
8.2.160.0070.00720.44
8.2.150.0060.00324.18
8.2.140.0000.00724.66
8.2.130.0000.00726.16
8.2.120.0040.00426.16
8.2.110.0070.00420.58
8.2.100.0080.00417.97
8.2.90.0040.00418.03
8.2.80.0040.00418.78
8.2.70.0000.00817.63
8.2.60.0000.00817.50
8.2.50.0000.00817.93
8.2.40.0030.00519.91
8.2.30.0040.00419.35
8.2.20.0050.00318.25
8.2.10.0070.00019.21
8.2.00.0000.00719.33
8.1.330.0110.00816.86
8.1.320.0150.00816.06
8.1.310.0040.00416.19
8.1.300.0030.00619.87
8.1.290.0040.00418.88
8.1.280.0040.01125.92
8.1.270.0080.00020.82
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0060.00320.88
8.1.230.0080.00317.71
8.1.220.0090.00017.91
8.1.210.0030.00518.77
8.1.200.0030.00617.35
8.1.190.0050.00517.22
8.1.180.0000.00818.10
8.1.170.0070.00017.62
8.1.160.0070.00018.91
8.1.150.0000.00818.97
8.1.140.0040.00420.95
8.1.130.0030.00320.04
8.1.120.0000.00717.52
8.1.110.0070.00017.38
8.1.100.0050.00317.49
8.1.90.0030.00317.38
8.1.80.0040.00417.36
8.1.70.0100.00017.36
8.1.60.0000.00817.55
8.1.50.0040.00417.51
8.1.40.0000.00817.50
8.1.30.0050.00317.67
8.1.20.0000.00817.69
8.1.10.0040.00417.58
8.1.00.0070.00017.56
8.0.300.0040.00418.77
8.0.290.0000.00716.75
8.0.280.0000.00718.37
8.0.270.0000.00717.29
8.0.260.0040.00420.09
8.0.250.0030.00317.00
8.0.240.0040.00416.92
8.0.230.0000.00716.98
8.0.220.0000.00716.90
8.0.210.0040.00416.95
8.0.200.0060.00017.00
8.0.190.0000.00716.96
8.0.180.0040.00416.96
8.0.170.0040.00716.79
8.0.160.0000.00816.88
8.0.150.0040.00416.80
8.0.140.0050.00216.88
8.0.130.0050.00013.29
8.0.120.0080.00016.84
8.0.110.0080.00016.97
8.0.100.0030.00316.79
8.0.90.0070.00016.97
8.0.80.0120.00316.86
8.0.70.0050.00516.78
8.0.60.0040.00416.81
8.0.50.0000.00716.89
8.0.30.0140.00516.84
8.0.20.0090.00917.30
8.0.10.0050.00216.98
8.0.00.0130.00816.79
7.4.330.0000.00415.55
7.4.320.0030.00316.43
7.4.300.0060.00016.61
7.4.290.0000.00716.50
7.4.280.0090.00316.49
7.4.270.0030.00316.65
7.4.260.0050.00013.28
7.4.250.0030.00316.49
7.4.240.0070.00016.50
7.4.230.0030.00316.56
7.4.220.0050.00316.49
7.4.210.0110.00516.58
7.4.200.0000.00716.71
7.4.130.0060.01516.58
7.4.120.0060.01216.59
7.4.110.0090.00916.73
7.4.100.0070.01016.51
7.4.90.0140.00316.58
7.4.80.0130.00719.39
7.4.70.0120.00816.65
7.4.60.0090.00616.57
7.4.50.0030.01316.52
7.4.40.0090.00616.43
7.4.00.0130.00314.83
7.3.330.0030.00316.41
7.3.320.0050.00013.24
7.3.310.0040.00416.36
7.3.300.0030.00316.25
7.3.290.0030.00316.37
7.3.280.0080.00816.13
7.3.260.0090.01016.43
7.3.240.0100.00816.46
7.3.230.0120.00616.46
7.3.210.0110.00616.54
7.3.200.0110.00516.30
7.3.190.0140.00316.38
7.3.180.0060.01016.67
7.3.170.0060.00916.35
7.3.160.0060.00916.61
7.3.80.0090.00415.14
7.3.70.0090.01314.96
7.3.60.0040.00814.77
7.3.50.0100.00314.70
7.3.40.0150.00514.57
7.3.30.0060.01114.88
7.3.20.0230.00315.06
7.3.10.0130.01014.81
7.3.00.0250.00014.48
7.2.330.0140.00316.53
7.2.320.0120.00616.47
7.2.310.0070.01416.79
7.2.300.0090.01516.81
7.2.290.0090.00916.60
7.2.210.0190.00414.96
7.2.200.0090.00615.13
7.2.190.0090.00515.02
7.2.180.0200.00015.05
7.2.170.0120.00515.00
7.2.160.0130.00415.07
7.2.150.0200.00714.87
7.2.140.0170.01415.08
7.2.130.0190.00315.04
7.2.120.0180.00914.75
7.2.110.1370.01615.04
7.2.100.0200.01014.85
7.2.90.0280.00715.02
7.2.80.0290.00415.04
7.2.70.0160.00514.73
7.2.60.0230.00714.74
7.2.50.0170.01014.72
7.2.40.0220.00914.94
7.2.30.0140.01115.00
7.2.20.0250.00315.00
7.2.10.0180.01414.80
7.2.00.0160.00414.67
7.1.310.0190.00613.90
7.1.300.0410.00013.81
7.1.290.0210.00314.06
7.1.280.0200.00313.77
7.1.270.0120.01514.11
7.1.260.0160.01013.65
7.1.250.0120.00813.77

preferences:
39.85 ms | 403 KiB | 5 Q