3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $data = null; public $parent = null; public $left = null; public $right = null; } function mirror_recursive($root) { if ($root === null) { return; } mirror_recursive($root->left); mirror_recursive($root->right); $temp = $root->left; $root->left = $root->right; $root->right = $temp; } function mirror_norec($root) { $queue = array(); array_unshift($queue, $root); while (!empty($queue)) { $cnode = array_pop($queue); if ($cnode->left !== null) array_unshift($queue, $cnode->left); if ($cnode->right !== null) array_unshift($queue, $cnode->right); $temp = $cnode->left; $cnode->left = $cnode->right; $cnode->right = $temp; } } function inorder_traverse($root) { if ($root->left !== null) inorder_traverse($root->left); echo $root->data . " "; if ($root->right !== null) inorder_traverse($root->right); } $root = new Node(); $n1 = new Node(); $n2 = new Node(); $n11 = new Node(); $n12 = new Node(); $n13 = new Node(); $n14 = new Node(); $n15 = new Node(); $n21 = new Node(); $root->data = 0; $n1->data = 1; $n2->data = 2; $n11->data = 11; $n12->data = 12; $n13->data = 13; $n14->data = 14; $n15->data = 15; $n21->data = 21; $root->left = $n1; $root->right = $n2; $n1->left = $n11; $n1->right = $n12; $n11->left = $n13; $n12->right = $n14; $n13->left = $n15; $n2->right = $n21; inorder_traverse($root); echo "<br>"; mirror_recursive($root); inorder_traverse($root); echo "<br>"; mirror_norec($root); inorder_traverse($root); ?>

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.60.0030.01316.48
8.3.50.0160.00916.54
8.3.40.0160.00420.32
8.3.30.0150.00318.67
8.3.20.0040.00418.69
8.3.10.0080.00018.95
8.3.00.0070.00319.38
8.2.180.0130.01016.63
8.2.170.0120.00322.96
8.2.160.0060.00822.15
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00420.69
8.2.110.0080.00022.25
8.2.100.0100.00020.54
8.1.280.0100.00725.92
8.1.270.0090.00023.78
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0030.00723.91
8.1.230.0030.00720.41
7.4.10.0250.00416.55
7.4.00.0080.00715.59
7.3.130.0140.01416.46
7.3.120.0060.01315.27
7.3.110.0130.00715.54
7.3.100.0080.01115.28
7.3.90.0070.00815.38
7.3.80.0110.01014.99
7.3.70.0080.00815.25
7.3.60.0120.00614.13
7.3.50.0090.01015.41
7.3.40.0080.01415.37
7.3.30.0060.01115.38
7.3.20.0350.00615.43
7.3.10.0220.00915.43
7.3.00.0220.00415.42
7.2.260.0180.01116.86
7.2.250.0120.00515.71
7.2.240.0090.01115.69
7.2.230.0090.01015.50
7.2.220.0110.01015.74
7.2.210.0090.01015.63
7.2.200.0120.00614.38
7.2.190.0110.01015.56
7.2.180.0130.00514.50
7.2.170.0120.00715.60
7.2.160.0120.00614.34
7.2.150.0380.01016.75
7.2.140.0120.00916.79
7.2.130.0320.01516.85
7.2.120.0290.00816.82
7.2.110.0350.00716.80
7.2.100.0290.01016.69
7.2.90.0360.01116.71
7.2.80.0100.00715.66
7.2.70.0110.00415.65
7.2.60.0380.00715.66
7.2.50.0290.00615.48
7.2.40.0070.00815.65
7.2.30.0320.01115.51
7.2.20.0080.01015.76
7.2.10.0110.00515.66
7.2.00.0180.00916.63
7.1.330.0350.00815.74
7.1.320.0450.00915.88
7.1.310.0340.01115.51
7.1.300.0350.00614.91
7.1.290.0360.00915.73
7.1.280.0260.00714.94
7.1.270.0300.00815.69
7.1.260.0350.00915.76
7.1.250.0190.01115.40
7.1.240.0070.01214.38
7.1.230.0140.00815.03
7.1.220.0430.01014.37
7.1.210.0090.00814.32
7.1.200.0400.00815.67
7.1.190.0620.00714.48
7.1.180.0160.00414.51
7.1.170.0550.00615.67
7.1.160.0440.00615.26
7.1.150.0540.00616.64
7.1.140.0450.01015.57
7.1.130.0560.01115.68
7.1.120.0470.00915.60
7.1.110.0170.00915.65
7.1.100.0310.01115.66
7.1.90.0480.00614.46
7.1.80.0090.01014.43
7.1.70.0390.00415.39
7.1.60.0160.00917.40
7.1.50.0340.00415.94
7.1.40.0500.00915.78
7.1.30.0470.00514.52
7.1.20.0390.00516.32
7.1.10.0290.00814.53
7.1.00.0360.02817.41
7.0.330.0320.01015.18
7.0.320.0440.00815.21
7.0.310.0550.00614.27
7.0.300.0340.00314.27
7.0.290.0380.00714.36
7.0.280.0670.00914.20
7.0.270.0380.00814.10
7.0.260.0290.00714.36
7.0.250.0610.00615.20
7.0.240.0240.00715.21
7.0.230.0110.00816.20
7.0.220.0410.00515.28
7.0.210.0110.00816.24
7.0.200.0070.01015.75
7.0.190.0280.00514.26
7.0.180.0290.00914.32
7.0.170.0100.01116.12
7.0.160.0330.00414.29
7.0.150.0540.01215.29
7.0.140.0210.03017.52
7.0.130.0350.00515.25
7.0.120.0360.02816.86
7.0.110.0440.00514.30
7.0.100.0460.00414.20
7.0.90.0500.00515.21
7.0.80.0490.00614.31
7.0.70.0420.00614.16
7.0.60.0360.03317.37
7.0.50.0380.02315.42
7.0.40.0100.03115.53
7.0.30.0150.01716.17
7.0.20.0150.02916.18
7.0.10.0070.02415.61
7.0.00.0080.03616.24
5.6.400.0140.01015.02
5.6.390.0100.00413.68
5.6.380.0120.00713.73
5.6.370.0140.01215.08
5.6.360.0070.01314.88
5.6.350.0220.00515.13
5.6.340.0190.00415.46
5.6.330.0170.00413.56
5.6.320.0160.00513.91
5.6.310.0110.00413.91
5.6.300.0080.00813.85
5.6.290.0130.00213.79
5.6.280.0080.02916.09
5.6.270.0130.00713.73
5.6.260.0110.00413.71
5.6.250.0120.00613.80
5.6.240.0160.00013.76
5.6.230.0110.00915.19
5.6.220.0130.00715.18
5.6.210.0100.03116.01
5.6.200.0140.03216.14
5.6.190.0160.03016.98
5.6.180.0370.01716.04
5.6.170.0100.01815.93
5.6.160.0120.01916.86
5.6.150.0070.02316.05
5.6.140.0100.01816.10
5.6.130.0110.03216.25
5.6.120.0080.03417.09
5.6.110.0110.02816.23
5.6.100.0090.02417.10
5.6.90.0120.02816.33
5.6.80.0080.03016.86
5.6.70.0110.00313.52
5.6.60.0070.01013.73
5.6.50.0140.00213.66
5.6.40.0120.00915.03
5.6.30.0120.00615.05
5.6.20.0080.01315.07
5.6.10.0120.00814.99
5.6.00.0090.00513.74
5.5.380.0130.01115.05
5.5.370.0110.00813.82
5.5.360.0090.00413.68
5.5.350.0050.02915.98
5.5.340.0050.03616.12
5.5.330.0090.02816.86
5.5.320.0200.02816.88
5.5.310.0220.02916.89
5.5.300.0100.01716.19
5.5.290.0100.03216.12
5.5.280.0120.03016.89
5.5.270.0050.02417.13
5.5.260.0070.03515.99
5.5.250.0130.02816.84
5.5.240.0120.03115.86
5.5.230.0070.00713.78
5.5.220.0120.00614.94
5.5.210.0110.00715.11
5.5.200.0100.00815.06
5.5.190.0090.00613.69
5.5.180.0140.00515.12
5.5.170.0110.01014.96
5.5.160.0130.00614.83
5.5.150.0090.00613.79
5.5.140.0090.00815.05
5.5.130.0080.01015.08
5.5.120.0110.00415.00
5.5.110.0070.01215.21
5.5.100.0100.01115.12
5.5.90.0100.00614.98
5.5.80.0100.00415.00
5.5.70.0120.00715.11
5.5.60.0070.01115.01
5.5.50.0050.01015.00
5.5.40.0080.00514.86
5.5.30.0070.01315.14
5.5.20.0070.01014.99
5.5.10.0120.00715.17
5.5.00.0120.01015.07
5.4.450.0080.03114.91
5.4.440.0090.03114.91
5.4.430.0080.02014.92
5.4.420.0040.02214.99
5.4.410.0040.01914.87
5.4.400.0080.03014.90
5.4.390.0060.03214.92
5.4.380.0070.02914.90
5.4.370.0050.02214.91
5.4.360.0070.03114.93
5.4.350.0080.02714.88
5.4.340.0060.02414.90
5.4.330.0050.00712.78
5.4.320.0110.02314.92
5.4.310.0040.03314.90
5.4.300.0110.02414.92
5.4.290.0040.02414.93
5.4.280.0060.03014.90
5.4.270.0060.02814.90
5.4.260.0070.02914.80
5.4.250.0090.02714.88
5.4.240.0110.02814.93
5.4.230.0080.01914.81
5.4.220.0080.02814.82
5.4.210.0050.02114.85
5.4.200.0060.01914.92
5.4.190.0060.02914.81
5.4.180.0100.02714.90
5.4.170.0050.03014.90
5.4.160.0030.02014.79
5.4.150.0090.02914.90
5.4.140.0060.02413.97
5.4.130.0070.03013.97
5.4.120.0070.02413.98
5.4.110.0070.01814.02
5.4.100.0070.01914.00
5.4.90.0050.02614.01
5.4.80.0090.01314.03
5.4.70.0050.01913.96
5.4.60.0060.03014.00
5.4.50.0040.01913.99
5.4.40.0050.01913.94
5.4.30.0080.02914.06
5.4.20.0030.03313.97
5.4.10.0110.02614.02
5.4.00.0090.02713.79
5.3.290.0090.03113.43
5.3.280.0100.02813.36
5.3.270.0060.02913.41
5.3.260.0030.03113.41
5.3.250.0070.02813.40
5.3.240.0060.02413.40
5.3.230.0070.03113.40
5.3.220.0100.02913.39
5.3.210.0070.02813.43
5.3.200.0050.01813.38
5.3.190.0090.01913.38
5.3.180.0060.02013.38
5.3.170.0070.01513.36
5.3.160.0050.02313.49
5.3.150.0100.01413.39
5.3.140.0070.01913.38
5.3.130.0050.03213.40
5.3.120.0090.03113.41
5.3.110.0040.03213.38
5.3.100.0080.01613.22
5.3.90.0080.02913.22
5.3.80.0050.02913.22
5.3.70.0060.01913.21
5.3.60.0040.02913.17
5.3.50.0090.02213.16
5.3.40.0100.02613.21
5.3.30.0070.02313.16
5.3.20.0080.03013.06
5.3.10.0070.02713.13
5.3.00.0020.02313.12
5.2.170.0100.05311.33
5.2.160.0070.05011.18
5.2.150.0200.05011.18
5.2.140.0000.04711.25
5.2.130.0000.07011.13
5.2.120.0030.06311.13
5.2.110.0030.05311.16
5.2.100.0000.03711.13
5.2.90.0030.04011.16
5.2.80.0100.02711.18
5.2.70.0070.05711.12
5.2.60.0100.05711.14
5.2.50.0070.06711.20
5.2.40.0130.03711.06
5.2.30.0030.04310.88
5.2.20.0100.05711.14
5.2.10.0070.05710.90
5.2.00.0030.06310.91
5.1.60.0030.05010.05
5.1.50.0000.02710.00
5.1.40.0030.03010.16
5.1.30.0030.02710.36
5.1.20.0000.03010.35
5.1.10.0030.02310.06
5.1.00.0070.04710.25
5.0.50.0030.0478.56
5.0.40.0070.0238.52
5.0.30.0030.0608.26
5.0.20.0030.0478.38
5.0.10.0030.0338.21
5.0.00.0030.0678.17
4.4.90.0000.0238.08
4.4.80.0000.0308.08
4.4.70.0070.0238.08
4.4.60.0070.0208.08
4.4.50.0030.0378.08
4.4.40.0030.0238.08
4.4.30.0000.0178.08
4.4.20.0000.0178.08
4.4.10.0000.0238.08
4.4.00.0030.0438.08
4.3.110.0030.0278.08
4.3.100.0100.0238.08
4.3.90.0030.0338.08
4.3.80.0030.0538.08
4.3.70.0000.0378.08
4.3.60.0000.0178.08
4.3.50.0030.0138.08
4.3.40.0030.0378.08
4.3.30.0030.0338.08
4.3.20.0000.0338.08
4.3.10.0000.0278.08
4.3.00.0000.0378.08

preferences:
48.37 ms | 401 KiB | 5 Q