3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * convert square definition from x,y,l (x,y, length) to x1,y1,x2,y2 */ function point($sq) { return array( 'x1' => $sq['x'], 'y1' => $sq['y'], 'x2' => $sq['x'] + $sq['l'], 'y2' => $sq['y'] + $sq['l'], ); } /* * return intersect square */ function intersect(array $ps) { $r = max(array_map(function($e) { return $e['x1']; }, $ps)); $l = min(array_map(function($e) { return $e['x2']; }, $ps)); $t = max(array_map(function($e) { return $e['y1']; }, $ps)); $b = min(array_map(function($e) { return $e['y2']; }, $ps)); if ($r < $l && $b > $t) { return array( 'x1' => $l, 'y1' => $b, 'x2' => $r, 'y2' => $t, ); } return false; } /* * return square area */ function area($sq) { return abs(($sq['x1'] - $sq['x2']) * ($sq['y1'] - $sq['y2'])); } // input data $sq1 = array('x' => 2, 'y' => 2, 'l' => 4); $sq2 = array('x' => 3, 'y' => 100, 'l' => 4); echo 'Intersect: ' . ((false !== $intersect = intersect(array(point($sq1), point($sq2)))) ? 'yes' : 'no') . PHP_EOL; if (false !== $intersect) { echo 'Area: ' . area($intersect) . PHP_EOL; }

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.40.0090.00618.67
8.3.30.0070.01118.85
8.3.20.0080.00018.81
8.3.10.0060.00320.48
8.3.00.0040.00417.34
8.2.170.0060.01322.96
8.2.160.0070.00722.14
8.2.150.0030.00625.66
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0080.00019.48
8.2.110.0090.00020.56
8.2.100.0040.00817.91
8.2.90.0030.00717.75
8.2.80.0050.00317.97
8.2.70.0000.00817.93
8.2.60.0040.00418.34
8.2.50.0030.00518.10
8.2.40.0000.00719.38
8.2.30.0000.00719.32
8.2.20.0070.00017.73
8.2.10.0000.00817.73
8.2.00.0040.00417.67
8.1.270.0080.00023.99
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0000.00820.70
8.1.230.0000.01118.99
8.1.220.0050.00217.78
8.1.210.0000.00818.77
8.1.200.0060.00317.35
8.1.190.0060.00317.35
8.1.180.0050.00318.10
8.1.170.0060.00318.50
8.1.160.0060.00318.82
8.1.150.0000.00918.81
8.1.140.0050.00217.34
8.1.130.0070.00017.89
8.1.120.0040.00417.46
8.1.110.0050.00317.36
8.1.100.0040.00417.47
8.1.90.0070.00017.36
8.1.80.0050.00317.47
8.1.70.0000.00717.50
8.1.60.0000.00917.48
8.1.50.0040.00417.45
8.1.40.0000.00917.53
8.1.30.0070.00017.49
8.1.20.0030.00517.69
8.1.10.0060.00317.52
8.1.00.0030.00717.54
8.0.300.0060.00318.77
8.0.290.0080.00016.63
8.0.280.0070.00018.40
8.0.270.0000.00717.23
8.0.260.0040.00416.81
8.0.250.0040.00416.93
8.0.240.0000.00816.91
8.0.230.0040.00416.87
8.0.220.0000.00716.80
8.0.210.0040.00416.78
8.0.200.0060.00016.95
8.0.190.0040.00416.83
8.0.180.0040.00416.86
8.0.170.0060.00316.82
8.0.160.0040.00416.87
8.0.150.0000.00816.75
8.0.140.0070.00316.74
8.0.130.0000.00513.27
8.0.120.0050.00316.75
8.0.110.0000.00716.79
8.0.100.0050.00316.75
8.0.90.0030.00516.93
8.0.80.0070.01116.78
8.0.70.0070.00016.97
8.0.60.0030.00416.79
8.0.50.0000.00716.72
8.0.30.0100.01017.31
8.0.20.0160.00217.18
8.0.10.0040.00416.87
8.0.00.0050.01316.71
7.4.330.0000.00514.71
7.4.320.0000.00716.53
7.4.300.0000.00616.61
7.4.290.0040.00416.59
7.4.280.0060.00316.63
7.4.270.0000.00716.63
7.4.260.0000.00513.27
7.4.250.0000.00816.57
7.4.240.0000.00716.52
7.4.230.0080.00016.70
7.4.220.0070.01016.64
7.4.210.0080.00816.63
7.4.200.0000.00716.60
7.4.190.0040.00416.70
7.4.160.0100.00716.41
7.4.150.0120.00817.07
7.4.140.0080.01117.22
7.4.130.0050.01116.50
7.4.120.0090.01116.52
7.4.110.0130.00616.32
7.4.100.0030.01416.52
7.4.90.0030.01916.32
7.4.80.0120.01218.80
7.4.70.0080.01416.28
7.4.60.0160.00016.50
7.4.50.0000.00823.42
7.4.40.0110.00421.69
7.4.30.0140.00316.50
7.4.00.0060.00914.78
7.3.330.0050.00013.21
7.3.320.0000.00713.20
7.3.310.0070.00016.39
7.3.300.0030.00316.42
7.3.290.0030.01016.38
7.3.280.0060.01016.34
7.3.270.0120.00617.07
7.3.260.0100.00618.24
7.3.250.0090.00916.46
7.3.240.0140.00316.28
7.3.230.0110.00616.65
7.3.210.0110.00616.75
7.3.200.0080.00819.39
7.3.190.0090.00916.46
7.3.180.0080.00816.42
7.3.170.0060.01616.32
7.3.160.0110.00516.61
7.3.120.0030.01314.59
7.3.10.0040.01116.47
7.3.00.0040.00816.88
7.2.330.0110.00716.63
7.2.320.0080.00816.93
7.2.310.0070.01016.50
7.2.300.0160.00816.57
7.2.290.0100.00716.63
7.2.130.0060.00316.93
7.2.120.0060.01016.98
7.2.110.0090.00616.55
7.2.100.0120.00016.69
7.2.90.0080.00417.04
7.2.80.0060.00616.97
7.2.70.0000.01116.87
7.2.60.0050.00716.97
7.2.50.0050.00817.06
7.2.40.0030.00717.06
7.2.30.0040.01117.01
7.2.20.0080.00616.91
7.2.10.0060.00316.94
7.2.00.0030.01417.20
7.1.250.0060.00615.82
7.1.200.0060.00615.76
7.1.70.0030.00716.82
7.1.60.0030.02119.40
7.1.50.0060.01616.93
7.1.00.0100.06322.44
7.0.200.0030.00716.79
7.0.140.0070.07022.16
7.0.120.0030.03322.04
7.0.60.0100.07019.89
7.0.50.0000.04317.98
7.0.40.0100.05020.22
7.0.30.0370.07020.08
7.0.20.0300.07320.23
7.0.10.0170.08020.16
7.0.00.0030.05720.07
5.6.280.0070.07020.90
5.6.210.0070.08020.64
5.6.200.0000.05018.19
5.6.190.0100.05720.62
5.6.180.2270.04320.61
5.6.170.0230.05020.39
5.6.160.0130.08020.52
5.6.150.0070.08018.13
5.6.140.0030.07718.23
5.6.130.0100.05018.18
5.6.120.0030.08721.15
5.6.110.0100.07321.02
5.6.100.0070.04021.10
5.6.90.0130.07721.11
5.6.80.0030.08720.42
5.5.350.0130.07320.30
5.5.340.0070.08018.02
5.5.330.0000.04320.21
5.5.320.0230.03720.30
5.5.310.1330.05020.41
5.5.300.0000.04317.99
5.5.290.0100.06318.07
5.5.280.0000.06020.79
5.5.270.0130.06720.69
5.5.260.0130.07320.98
5.5.250.0130.05720.51
5.5.240.0230.07320.25
5.4.450.0070.05019.60
5.4.440.0070.04019.45
5.4.430.0030.05319.52
5.4.420.0130.05719.56
5.4.410.0100.04319.32
5.4.400.0130.07019.13
5.4.390.0030.07019.16
5.4.380.0100.07018.85
5.4.370.0130.07318.88
5.4.360.0130.06718.93
5.4.350.0130.07319.15
5.4.340.0130.03018.92
5.4.320.0230.05318.92
5.4.310.0130.06719.12
5.4.300.0070.05018.85
5.4.290.0130.07319.11
5.4.280.0030.07719.14
5.4.270.0000.05019.15
5.4.260.0100.04319.23
5.4.250.0170.06018.91
5.4.240.0130.06719.15
5.4.230.0070.05719.14
5.4.220.0030.04318.84
5.4.210.0100.07318.97
5.4.200.0130.05319.13
5.4.190.0030.08019.12
5.4.180.0100.07319.23
5.4.170.0070.05018.87
5.4.160.0030.05019.22
5.4.150.0030.04318.84
5.4.140.0070.04716.55
5.4.130.0070.07016.46
5.4.120.0100.07316.41
5.4.110.0030.07716.36
5.4.100.0030.05716.48
5.4.90.0070.07316.46
5.4.80.0130.03716.33
5.4.70.0130.05716.46
5.4.60.0100.03316.45
5.4.50.0200.06016.40
5.4.40.0100.05716.31
5.4.30.0130.06716.40
5.4.20.0100.04316.39
5.4.10.0030.08016.27
5.4.00.0130.06315.82
5.3.290.0100.07314.71
5.3.280.0100.03314.50
5.3.270.0000.04714.52
5.3.260.0030.07014.67
5.3.250.0070.04314.77
5.3.240.0100.07014.70
5.3.230.0070.07714.64
5.3.220.0070.07314.59
5.3.210.0070.06014.64
5.3.200.0070.05314.63
5.3.190.0170.06314.64
5.3.180.0100.07314.58
5.3.170.0030.07314.58
5.3.160.0100.07014.63
5.3.150.0170.06014.61
5.3.140.0070.07714.50
5.3.130.0070.04714.57
5.3.120.0100.07714.71
5.3.110.0100.07014.61
5.3.100.0030.07714.09
5.3.90.0030.08014.18
5.3.80.0030.08014.07
5.3.70.0030.05314.05
5.3.60.0100.07014.09
5.3.50.0100.06014.00
5.3.40.0030.06314.02
5.3.30.0000.07313.93
5.3.20.0100.06013.70
5.3.10.0130.06313.68
5.3.00.0070.06013.62
5.2.170.0100.05711.16
5.2.160.0030.05011.07
5.2.150.0030.05311.04
5.2.140.0100.04311.11
5.2.130.0000.06311.27
5.2.120.0030.06011.05
5.2.110.0070.06011.16
5.2.100.0030.03711.11
5.2.90.0030.06711.11
5.2.80.0070.06311.09
5.2.70.0070.05011.09
5.2.60.0070.06011.09
5.2.50.0000.06711.07
5.2.40.0100.06011.04
5.2.30.0170.04711.12
5.2.20.0030.06310.97
5.2.10.0070.06310.89
5.2.00.0000.06310.79
5.1.60.0000.0279.97
5.1.50.0000.0339.91
5.1.40.0030.0539.89
5.1.30.0070.04010.23
5.1.20.0030.06010.31
5.1.10.0000.04710.02
5.1.00.0070.03710.14
5.0.50.0030.0208.61
5.0.40.0030.0478.57
5.0.30.0030.0338.29
5.0.20.0030.0378.17
5.0.10.0070.0378.20
5.0.00.0000.0378.18
4.4.90.0030.0337.85
4.4.80.0000.0377.85
4.4.70.0070.0277.85
4.4.60.0030.0177.85
4.4.50.0000.0377.85
4.4.40.0000.0507.85
4.4.30.0000.0407.85
4.4.20.0130.0237.85
4.4.10.0000.0377.85
4.4.00.0030.0537.85
4.3.110.0000.0237.66
4.3.100.0000.0177.66
4.3.90.0030.0337.66
4.3.80.0000.0277.66
4.3.70.0000.0207.66
4.3.60.0000.0177.66
4.3.50.0000.0177.66
4.3.40.0000.0237.66
4.3.30.0030.0137.66
4.3.20.0000.0177.66
4.3.10.0000.0177.66
4.3.00.0030.0137.66

preferences:
45.07 ms | 400 KiB | 5 Q