3v4l.org

run code in 300+ PHP versions simultaneously
<?php function knapsackLight($value1, $weight1, $value2, $weight2, $maxW) { $results[0] = $maxW >= $weight1 && $value1 ? $value1 : null; $results[1] = $maxW >= $weight2 && $value2 ? $value2 : null; $results[2] = $maxW >= $weight1 + $weight2 && $value1 + $value2 ? $value1 + $value2 : null; return max($results[0], $results[1], $results[2]); } 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.3.130.0000.01518.29
8.3.120.0130.00718.95
8.3.110.0160.00320.94
8.3.100.0090.00024.06
8.3.90.0030.00626.77
8.3.80.0080.00016.63
8.3.70.0090.00616.75
8.3.60.0070.01418.31
8.3.50.0120.00417.23
8.3.40.0090.00618.79
8.3.30.0120.00418.58
8.3.20.0060.00320.70
8.3.10.0020.00522.09
8.3.00.0040.00423.66
8.2.250.0040.00418.45
8.2.240.0090.00918.98
8.2.230.0030.00622.58
8.2.220.0070.00437.54
8.2.210.0070.00726.77
8.2.200.0000.00916.60
8.2.190.0160.00016.75
8.2.180.0110.00718.16
8.2.170.0110.00422.96
8.2.160.0110.00320.39
8.2.150.0060.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0100.00019.95
8.2.110.0070.00322.11
8.2.100.0040.00817.91
8.2.90.0030.00517.91
8.2.80.0040.00417.97
8.2.70.0040.00417.93
8.2.60.0000.00718.16
8.2.50.0080.00018.10
8.2.40.0040.00419.52
8.2.30.0050.00219.24
8.2.20.0040.00418.02
8.2.10.0040.00419.32
8.2.00.0040.00419.20
8.1.300.0130.00317.97
8.1.290.0030.00618.88
8.1.280.0040.01125.92
8.1.270.0040.00420.81
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00722.21
8.1.230.0000.01120.89
8.1.220.0040.00717.74
8.1.210.0050.00318.77
8.1.200.0040.00817.22
8.1.190.0050.00317.35
8.1.180.0090.00018.10
8.1.170.0030.00518.52
8.1.160.0000.00718.89
8.1.150.0040.00418.84
8.1.140.0060.00320.86
8.1.130.0000.00820.28
8.1.120.0000.00717.33
8.1.110.0040.00417.45
8.1.100.0030.00617.41
8.1.90.0070.00017.42
8.1.80.0050.00317.50
8.1.70.0030.00617.44
8.1.60.0080.00017.51
8.1.50.0000.00717.51
8.1.40.0030.00617.52
8.1.30.0040.00417.63
8.1.20.0040.00417.61
8.1.10.0000.00717.48
8.1.00.0080.00017.41
8.0.300.0050.00319.67
8.0.290.0090.00016.63
8.0.280.0000.00718.41
8.0.270.0030.00316.77
8.0.260.0000.00719.97
8.0.250.0050.00216.94
8.0.240.0030.00516.85
8.0.230.0000.00816.94
8.0.220.0030.00316.89
8.0.210.0030.00316.76
8.0.200.0030.00316.93
8.0.190.0000.00816.85
8.0.180.0070.00016.90
8.0.170.0060.00616.84
8.0.160.0000.00716.74
8.0.150.0030.00316.77
8.0.140.0070.00016.78
8.0.130.0000.00513.37
8.0.120.0040.00416.76
8.0.110.0000.00716.82
8.0.100.0080.00016.71
8.0.90.0040.00416.82
8.0.80.0070.01316.89
8.0.70.0000.00716.67
8.0.60.0050.00316.70
8.0.50.0040.00416.65
8.0.30.0120.00617.12
8.0.20.0070.01117.00
8.0.10.0040.00416.89
8.0.00.0120.00816.87
7.4.330.0000.00515.55
7.4.320.0000.00616.52
7.4.300.0030.00316.45
7.4.290.0000.00716.53
7.4.280.0040.01016.53
7.4.270.0070.00016.60
7.4.260.0030.00313.25
7.4.250.0040.00416.46
7.4.240.0030.00316.63
7.4.230.0050.00216.37
7.4.220.0050.00216.61
7.4.210.0090.00916.58
7.4.200.0030.00316.54
7.4.130.0090.01016.66
7.4.120.0120.00616.67
7.4.110.0130.00316.59
7.4.100.0070.01016.35
7.4.90.0190.00016.59
7.4.80.0090.00919.39
7.4.70.0060.01016.58
7.4.60.0070.01016.24
7.4.50.0040.01116.22
7.4.40.0100.00616.43
7.4.00.0060.00914.97
7.3.330.0000.00716.35
7.3.320.0060.00013.40
7.3.310.0070.00016.25
7.3.300.0030.00316.34
7.3.290.0040.00416.31
7.3.280.0100.01016.38
7.3.260.0120.00616.50
7.3.240.0130.00516.45
7.3.230.0100.00616.38
7.3.210.0090.00616.46
7.3.200.0160.00716.23
7.3.190.0070.00716.67
7.3.180.0030.01316.28
7.3.170.0050.01116.25
7.3.160.0100.00716.31
7.3.80.0080.00814.80
7.3.70.0070.01014.82
7.3.60.0040.00814.79
7.3.50.0060.01214.92
7.3.40.0050.01014.85
7.3.30.0100.00614.86
7.3.20.0190.00014.87
7.3.10.0150.00614.89
7.3.00.0220.00314.82
7.2.330.0070.01116.48
7.2.320.0130.00316.43
7.2.310.0060.01516.57
7.2.300.0060.01016.53
7.2.290.0060.01116.77
7.2.210.0100.00715.14
7.2.200.0060.01215.12
7.2.190.0030.01014.84
7.2.180.0160.00014.84
7.2.170.0000.01714.77
7.2.160.0090.00914.91
7.2.150.0240.00615.11
7.2.140.0180.00614.99
7.2.130.0250.00315.19
7.2.120.0860.00714.69
7.2.110.0180.00714.87
7.2.100.0190.00614.87
7.2.90.0130.01015.15
7.2.80.0150.00615.05
7.2.70.0220.01014.77
7.2.60.0090.01315.00
7.2.50.0180.00314.76
7.2.40.0210.00015.21
7.2.30.0150.00615.06
7.2.20.0190.00315.15
7.2.10.0160.01215.01
7.2.00.0200.00715.04
7.1.310.0400.00714.20
7.1.300.0190.00413.79
7.1.290.0160.00914.00
7.1.280.0150.01114.12
7.1.270.0130.00713.95
7.1.260.0150.01213.68
7.1.250.0200.00713.77

preferences:
77.45 ms | 403 KiB | 5 Q