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 build_cbtree($a) { $root = new Node(); $root->data = $a[0]; for ($i = 1; $i < count($a); $i++) { $node = new Node(); $node->data = $a[$i]; insert_node($root, $node); } return $root; } #插入完全二叉树节点 function insert_node($root, $inode) { #使用树的广度优先遍历顺序取出节点,直到找到第一个左右子节点没满的节点,将待插入节点插入节点左边或右边 $queue = array(); array_unshift($queue, $root); while (!empty($queue)) { $cnode = array_pop($queue); if ($cnode->left == null) { $cnode->left = $inode; $inode->parent = $cnode; return $root; } else { array_unshift($queue, $cnode->left); } if ($cnode->right == null) { $cnode->right = $inode; $inode->parent = $cnode; return $root; } else { array_unshift($queue, $cnode->right); } } return $root; } #树的广度优先遍历 function bf_traverse($root) { $queue = array(); array_unshift($queue, $root); while (!empty($queue)) { $cnode = array_pop($queue); echo $cnode->data . " "; if ($cnode->left !== null) array_unshift($queue, $cnode->left); if ($cnode->right !== null) array_unshift($queue, $cnode->right); } echo "<br>"; } $a = array(9, 8, 7, 6, 8, 4, 3, 2, 1); $root = build_cbtree($a); bf_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.70.0110.01116.63
8.3.60.0130.00316.61
8.3.50.0120.00816.47
8.3.40.0120.00318.88
8.3.30.0070.00718.81
8.3.20.0090.00018.90
8.3.10.0060.00318.47
8.3.00.0030.00619.38
8.2.180.0110.01116.37
8.2.170.0060.00922.96
8.2.160.0140.00019.01
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0030.00618.04
8.2.110.0070.00422.24
8.2.100.0030.00717.78
8.2.90.0030.00619.21
8.2.80.0000.00817.97
8.2.70.0000.00817.63
8.2.60.0000.00818.05
8.2.50.0030.00619.78
8.2.40.0030.00619.22
8.2.30.0030.00717.68
8.2.20.0090.00017.87
8.2.10.0040.00417.72
8.2.00.0060.00317.82
8.1.280.0090.00925.92
8.1.270.0030.00523.99
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0040.00419.13
8.1.230.0060.00619.17
8.1.220.0080.00017.74
8.1.210.0060.00318.77
8.1.200.0000.01017.60
8.1.190.0040.00417.48
8.1.180.0050.00318.10
8.1.170.0040.00418.53
8.1.160.0040.00419.09
8.1.150.0040.00418.74
8.1.140.0000.00717.51
8.1.130.0000.00719.23
8.1.120.0070.00017.52
8.1.110.0040.00417.41
8.1.100.0000.00717.43
8.1.90.0000.00717.55
8.1.80.0040.00417.50
8.1.70.0030.00517.45
8.1.60.0000.00817.60
8.1.50.0040.00417.49
8.1.40.0000.00717.50
8.1.30.0000.00817.57
8.1.20.0080.00317.67
8.1.10.0050.00317.60
8.1.00.0000.00817.58
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0000.00718.68
8.0.270.0030.00317.28
8.0.260.0000.00716.86
8.0.250.0000.00817.09
8.0.240.0040.00417.03
8.0.230.0040.00416.96
8.0.220.0000.00817.02
8.0.210.0000.00716.88
8.0.200.0080.00016.97
8.0.190.0050.00317.04
8.0.180.0030.00716.87
8.0.170.0060.00316.86
8.0.160.0050.00316.99
8.0.150.0040.00416.84
8.0.140.0000.00816.88
8.0.130.0000.00713.42
8.0.120.0000.00816.79
8.0.110.0040.00416.82
8.0.100.0050.00216.98
8.0.90.0040.00417.01
8.0.80.0130.00616.83
8.0.70.0040.00416.82
8.0.60.0080.00016.98
8.0.50.0000.00816.95
8.0.30.0070.01017.05
8.0.20.0160.01017.21
8.0.10.0000.00716.91
8.0.00.0100.00816.87
7.4.330.0020.00212.97
7.4.320.0030.00316.46
7.4.300.0000.00616.58
7.4.290.0030.00316.48
7.4.280.0060.00316.61
7.4.270.0030.00316.55
7.4.260.0070.00013.23
7.4.250.0000.01016.49
7.4.240.0000.00716.57
7.4.230.0030.00316.65
7.4.220.0070.01716.66
7.4.210.0090.00616.57
7.4.200.0030.00316.55
7.4.190.0050.00316.74
7.4.160.0070.00716.73
7.4.150.0120.00616.57
7.4.140.0140.00317.86
7.4.130.0120.01216.51
7.4.120.0120.00616.36
7.4.110.0090.00916.52
7.4.100.0060.01216.68
7.4.90.0000.01716.62
7.4.80.0130.00319.39
7.4.70.0120.00816.64
7.4.60.0080.01116.55
7.4.50.0000.00616.26
7.4.40.0090.00616.38
7.4.30.0060.01116.51
7.4.10.0070.01114.75
7.4.00.0070.00815.25
7.3.330.0030.00313.42
7.3.320.0030.00313.26
7.3.310.0030.00516.31
7.3.300.0070.00016.27
7.3.290.0080.00516.31
7.3.280.0070.00716.26
7.3.270.0130.00716.57
7.3.260.0140.00416.38
7.3.240.0140.00316.48
7.3.230.0040.01216.45
7.3.210.0070.01116.48
7.3.200.0090.00916.34
7.3.190.0080.01416.43
7.3.180.0100.00716.25
7.3.170.0100.00616.49
7.3.160.0130.00316.45
7.3.130.0060.01215.21
7.3.120.0030.01414.95
7.3.110.0110.00714.95
7.3.100.0040.01114.72
7.3.90.0080.00314.68
7.3.80.0100.00014.76
7.3.70.0060.01014.73
7.3.60.0040.01114.50
7.3.50.0110.00414.81
7.3.40.0040.00814.50
7.3.30.0070.00715.00
7.3.20.0040.01116.73
7.3.10.0030.01116.73
7.3.00.0000.01316.67
7.2.330.0150.00316.47
7.2.320.0110.01616.66
7.2.310.0100.01416.90
7.2.300.0050.01116.87
7.2.290.0070.01016.60
7.2.260.0090.00914.84
7.2.250.0040.01415.23
7.2.240.0070.00715.16
7.2.230.0000.01715.19
7.2.220.0030.01414.91
7.2.210.0040.01115.01
7.2.200.0070.01014.94
7.2.190.0030.00914.82
7.2.180.0030.01215.13
7.2.170.0040.01214.72
7.2.160.0100.01015.07
7.2.150.0130.00317.11
7.2.140.0110.00316.55
7.2.130.0090.00416.79
7.2.120.0030.00716.96
7.2.110.0060.00616.98
7.2.100.0070.00716.76
7.2.90.0030.01216.99
7.2.80.0080.00916.72
7.2.70.0060.00816.89
7.2.60.0050.01216.84
7.2.50.0070.01017.04
7.2.40.0000.01017.03
7.2.30.0060.01016.83
7.2.20.0040.01116.79
7.2.10.0090.00316.79
7.2.00.0050.01218.19
7.1.330.0060.00915.97
7.1.320.0070.00716.08
7.1.310.0030.01015.78
7.1.300.0060.00315.70
7.1.290.0040.00715.62
7.1.280.0070.00715.84
7.1.270.0060.01215.95
7.1.260.0000.01115.86
7.1.250.0070.00715.52
7.1.240.0040.00815.80
7.1.230.0030.00615.81
7.1.220.0100.00715.60
7.1.210.0060.00615.96
7.1.200.0020.01115.73
7.1.190.0060.00615.55
7.1.180.0090.00615.89
7.1.170.0030.00915.46
7.1.160.0110.00015.73
7.1.150.0060.00815.68
7.1.140.0000.00915.80
7.1.130.0060.00615.55
7.1.120.0030.01115.95
7.1.110.0040.01215.58
7.1.100.0080.01016.79
7.1.90.0110.00415.96
7.1.80.0070.01015.56
7.1.70.0080.00516.44
7.1.60.0050.01417.63
7.1.50.0050.01416.34
7.1.40.0130.00315.62
7.1.30.0030.01315.87
7.1.20.0040.01115.96
7.1.10.0060.01215.44
7.1.00.0040.03019.01
7.0.330.0070.00715.60
7.0.320.0030.01315.37
7.0.310.0000.01415.29
7.0.300.0070.00415.49
7.0.290.0000.00815.55
7.0.280.0070.00715.20
7.0.270.0000.00815.20
7.0.260.0040.01115.56
7.0.250.0060.00615.23
7.0.240.0030.00815.65
7.0.230.0030.01015.55
7.0.220.0030.01315.30
7.0.210.0030.01015.31
7.0.200.0040.00816.13
7.0.190.0050.00515.52
7.0.180.0120.00315.51
7.0.170.0030.00615.45
7.0.160.0060.00615.20
7.0.150.0140.00315.41
7.0.140.0060.04118.76
7.0.130.0000.01515.60
7.0.120.0070.00715.55
7.0.110.0040.01115.48
7.0.100.0000.01015.50
7.0.90.0030.01315.39
7.0.80.0110.00015.54
7.0.70.0100.00315.40
7.0.60.0060.04517.56
7.0.50.0050.04416.69
7.0.40.0100.04416.83
7.0.30.0250.03016.88
7.0.20.0220.04316.70
7.0.10.0230.02816.79
7.0.00.0070.04716.76
5.6.400.0040.01114.61
5.6.390.0100.00714.63
5.6.380.0070.00714.45
5.6.370.0090.00314.31
5.6.360.0120.00614.39
5.6.350.0070.00714.47
5.6.340.0000.01214.45
5.6.330.0090.00414.49
5.6.320.0000.01014.64
5.6.310.0070.01014.48
5.6.300.0060.01214.64
5.6.290.0000.01114.52
5.6.280.0080.03417.54
5.6.270.0000.01414.37
5.6.260.0030.01314.54
5.6.250.0030.01314.60
5.6.240.0090.00914.71
5.6.230.0030.01014.39
5.6.220.0120.00614.29
5.6.210.0150.03417.45
5.6.200.0030.02816.30
5.6.190.0110.04117.72
5.6.180.2120.02217.58
5.6.170.0170.04017.54
5.6.160.0100.03817.62
5.6.150.0050.02316.35
5.6.140.0060.02316.26
5.6.130.0070.03816.38
5.6.120.0020.03017.76
5.6.110.0120.04017.94
5.6.100.0050.04017.67
5.6.90.0020.02717.66
5.6.80.0080.02517.39
5.6.70.0130.03317.49
5.6.60.0040.00414.27
5.6.50.0070.00714.62
5.6.40.0030.00614.35
5.6.30.0070.00714.32
5.6.20.0030.01014.23
5.6.10.0030.00714.37
5.6.00.0070.00714.25
5.5.380.0060.01214.33
5.5.370.0060.00614.36
5.5.360.0090.00914.60
5.5.350.0170.03817.40
5.5.340.0050.03416.16
5.5.330.0070.04517.49
5.5.320.0150.04017.48
5.5.310.0130.03917.33
5.5.300.0030.03016.04
5.5.290.0060.02516.26
5.5.280.0090.04517.55
5.5.270.0050.04717.63
5.5.260.0040.04817.66
5.5.250.0110.03817.59
5.5.240.0060.03817.31
5.5.230.0090.00314.16
5.5.220.0030.00714.16
5.5.210.0060.00614.46
5.5.200.0040.00714.41
5.5.190.0040.01114.51
5.5.180.0030.01014.18
5.5.170.0040.01114.37
5.5.160.0110.00014.31
5.5.150.0070.00714.21
5.5.140.0030.00914.44
5.5.130.0070.00714.21
5.5.120.0070.01014.36
5.5.110.0000.01714.23
5.5.100.0030.01314.31
5.5.90.0040.01214.30
5.5.80.0080.01114.25
5.5.70.0070.00713.92
5.5.60.0110.00714.43
5.5.50.0090.00314.52
5.5.40.0060.00614.63
5.5.30.0000.01214.02
5.5.20.0030.01014.50
5.5.10.0030.00714.48
5.5.00.0090.00314.41
5.4.450.0050.02615.25
5.4.440.0110.02315.36
5.4.430.0050.03615.23
5.4.420.0140.02015.39
5.4.410.0110.03815.21
5.4.400.0070.04215.14
5.4.390.0050.03515.23
5.4.380.0020.03615.16
5.4.370.0120.03315.26
5.4.360.0080.04015.16
5.4.350.0120.01915.28
5.4.340.0030.02315.28
5.4.330.0000.01011.31
5.4.320.0080.04015.09
5.4.310.0070.03815.27
5.4.300.0030.04515.09
5.4.290.0100.02315.25
5.4.280.0100.02515.27
5.4.270.0090.02315.28
5.4.260.0070.04015.27
5.4.250.0040.02415.25
5.4.240.0050.02215.23
5.4.230.0080.03915.27
5.4.220.0080.03715.22
5.4.210.0070.02215.19
5.4.200.0170.03015.27
5.4.190.0070.03915.19
5.4.180.0080.04015.23
5.4.170.0060.03615.31
5.4.160.0110.03615.11
5.4.150.0080.02815.27
5.4.140.0030.03313.83
5.4.130.0030.02413.91
5.4.120.0070.02513.85
5.4.110.0020.02713.89
5.4.100.0080.03813.89
5.4.90.0060.02313.87
5.4.80.0070.03913.88
5.4.70.0020.04413.94
5.4.60.0060.02513.93
5.4.50.0040.02613.79
5.4.40.0080.03613.86
5.4.30.0020.02513.88
5.4.20.0070.02013.96
5.4.10.0070.01913.87
5.4.00.0020.02713.53
5.3.290.0020.04512.99
5.3.280.0090.03812.92
5.3.270.0100.03712.98
5.3.260.0050.02712.97
5.3.250.0020.02413.04
5.3.240.0000.04112.99
5.3.230.0030.04613.05
5.3.220.0060.03812.96
5.3.210.0050.04212.95
5.3.200.0080.02312.95
5.3.190.0040.03012.91
5.3.180.0040.04112.96
5.3.170.0070.04213.02
5.3.160.0050.02312.96
5.3.150.0020.04412.94
5.3.140.0090.03512.95
5.3.130.0070.02012.94
5.3.120.0060.02112.88
5.3.110.0050.02313.02
5.3.100.0030.04612.69
5.3.90.0030.03112.67
5.3.80.0070.02212.67
5.3.70.0030.02412.67
5.3.60.0050.04012.69
5.3.50.0100.03612.62
5.3.40.0040.02512.65
5.3.30.0020.03212.70
5.3.20.0050.01812.51
5.3.10.0110.03312.46
5.3.00.0050.03312.55
5.2.170.0070.03311.32
5.2.160.0070.06011.14
5.2.150.0030.06311.33
5.2.140.0070.03311.16
5.2.130.0000.03711.12
5.2.120.0030.02711.27
5.2.110.0130.05311.01
5.2.100.0030.03011.27
5.2.90.0070.02711.16
5.2.80.0070.03311.07
5.2.70.0130.02711.00
5.2.60.0070.06311.02
5.2.50.0030.06311.10
5.2.40.0130.05710.98
5.2.30.0070.06010.95
5.2.20.0030.06011.00
5.2.10.0070.04310.89
5.2.00.0070.07010.75
5.1.60.0070.04010.04
5.1.50.0030.04710.03
5.1.40.0100.02710.15
5.1.30.0070.03310.41
5.1.20.0000.03310.52
5.1.10.0000.03010.00
5.1.00.0070.02310.05
5.0.50.0070.0438.50
5.0.40.0070.0438.50
5.0.30.0070.0608.28
5.0.20.0030.0408.23
5.0.10.0000.0378.22
5.0.00.0030.0408.10
4.4.90.0070.0277.79
4.4.80.0100.0277.79
4.4.70.0000.0337.79
4.4.60.0000.0407.79
4.4.50.0030.0337.79
4.4.40.0000.0537.79
4.4.30.0100.0207.79
4.4.20.0030.0177.79
4.4.10.0030.0237.79
4.4.00.0030.0477.79
4.3.110.0100.0307.79
4.3.100.0000.0307.79
4.3.90.0030.0207.79
4.3.80.0070.0507.79
4.3.70.0000.0207.79
4.3.60.0000.0207.79
4.3.50.0030.0177.79
4.3.40.0000.0377.79
4.3.30.0100.0177.79
4.3.20.0030.0177.79
4.3.10.0000.0337.79
4.3.00.0000.0237.79

preferences:
55.02 ms | 401 KiB | 5 Q