3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Tree data structure class BinaryNode { public $value = null; // node value public $left = null; // left child public $right = null; // right child public function __construct($value) { $this->value = $value; } } /** * invertTree function goes here */ function invertTree($node) { if($node == null){ return null; } $left = invertTree($node->left); $right = invertTree($node->right); $node->left = $right; $node->right = $left; return $node; } $root = new BinaryNode(1); $rootLeftChild = new BinaryNode(2); $rootRightChild = new BinaryNode(3); $rootLeftChildLeftChild = new BinaryNode(4); $rootLeftChildRightNode = new BinaryNode(5); $rootRightChildLeftChild = new BinaryNode(6); $rootRightChildRightNode = new BinaryNode(7); $rootLeftChild->left = $rootLeftChildLeftChild; $rootLeftChild->right = $rootLeftChildRightNode; $rootRightChild->left = $rootRightChildLeftChild; $rootRightChild->right = $rootRightChildRightNode; $root->left = $rootLeftChild; $root->right = $rootRightChild; $invertedTree = invertTree($root); var_dump($invertedTree->value == 1); var_dump($invertedTree->left->value == 3); var_dump($invertedTree->right->value == 2); var_dump($invertedTree->left->left->value == 7); var_dump($invertedTree->left->right->value == 8); var_dump($invertedTree->right->left->value == 5); var_dump($invertedTree->right->right->value == 4);

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.0120.00318.56
8.3.50.0120.00916.41
8.3.40.0070.00718.65
8.3.30.0070.00718.38
8.3.20.0070.00719.00
8.3.10.0040.00420.93
8.3.00.0040.00423.69
8.2.180.0120.00616.75
8.2.170.0140.00022.96
8.2.160.0030.01220.49
8.2.150.0000.00824.18
8.2.140.0000.00724.66
8.2.130.0030.00919.70
8.2.120.0000.00826.35
8.2.110.0090.00020.51
8.2.100.0040.00817.72
8.2.90.0040.00417.63
8.2.80.0000.00818.66
8.2.70.0030.00617.80
8.2.60.0000.00818.04
8.2.50.0080.00018.10
8.2.40.0040.00419.42
8.2.30.0000.00719.49
8.2.20.0000.00718.17
8.2.10.0000.00818.01
8.2.00.0030.00719.53
8.1.280.0110.00725.92
8.1.270.0040.00422.15
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00318.82
8.1.230.0080.00322.07
8.1.220.0030.00517.74
8.1.210.0090.00018.77
8.1.200.0000.00817.48
8.1.190.0000.00817.35
8.1.180.0030.00618.10
8.1.170.0030.00618.57
8.1.160.0040.00418.85
8.1.150.0050.00219.00
8.1.140.0040.00417.62
8.1.130.0050.00519.04
8.1.120.0060.00317.49
8.1.110.0000.00717.51
8.1.100.0030.00617.50
8.1.90.0050.00317.53
8.1.80.0040.00417.39
8.1.70.0000.00717.41
8.1.60.0090.00017.69
8.1.50.0040.00417.56
8.1.40.0040.00417.55
8.1.30.0000.00817.53
8.1.20.0040.00717.68
8.1.10.0000.00717.67
8.1.00.0060.00617.54
8.0.300.0070.00018.77
8.0.290.0060.00316.75
8.0.280.0000.00718.53
8.0.270.0030.00317.24
8.0.260.0030.00317.30
8.0.250.0030.00416.97
8.0.240.0080.00017.05
8.0.230.0000.00717.00
8.0.220.0070.00016.98
8.0.210.0030.00316.84
8.0.200.0030.00516.89
8.0.190.0080.00017.01
8.0.180.0000.00816.98
8.0.170.0000.01016.99
8.0.160.0030.00316.90
8.0.150.0060.00316.86
8.0.140.0050.00316.92
8.0.130.0030.00313.34
8.0.120.0040.00416.91
8.0.110.0040.00416.76
8.0.100.0050.00216.89
8.0.90.0070.00016.77
8.0.80.0100.00916.92
8.0.70.0070.00017.00
8.0.60.0000.00716.96
8.0.50.0040.00416.89
8.0.30.0130.00517.11
8.0.20.0160.00317.40
8.0.10.0000.00717.01
8.0.00.0030.01617.11
7.4.330.0000.00515.55
7.4.320.0000.00616.52
7.4.300.0060.00016.49
7.4.290.0070.00016.63
7.4.280.0040.00416.55
7.4.270.0030.00316.56
7.4.260.0000.00716.63
7.4.250.0030.00416.53
7.4.240.0030.00316.56
7.4.230.0000.00716.44
7.4.220.0000.00816.62
7.4.210.0030.01216.56
7.4.200.0000.00716.39
7.4.160.0100.00816.61
7.4.140.0090.00817.86
7.4.130.0080.01516.44
7.4.120.0120.00916.55
7.4.110.0070.01016.49
7.4.100.0100.00716.41
7.4.90.0060.01216.58
7.4.80.0060.01619.39
7.4.70.0070.01016.64
7.4.60.0080.00816.39
7.4.50.0100.00716.68
7.4.40.0100.01316.55
7.4.00.0070.01015.03
7.3.330.0030.00313.45
7.3.320.0060.00013.39
7.3.310.0000.00716.49
7.3.300.0030.00316.32
7.3.290.0000.00716.36
7.3.280.0070.00916.38
7.3.260.0080.01216.42
7.3.240.0100.00616.54
7.3.230.0090.00916.68
7.3.210.0160.00816.45
7.3.200.0100.00716.56
7.3.190.0160.00316.44
7.3.180.0070.01016.34
7.3.170.0100.01116.43
7.3.160.0030.01416.52
7.2.330.0130.01016.61
7.2.320.0030.01516.74
7.2.310.0150.00316.73
7.2.300.0070.01016.55
7.2.290.0100.01416.59
7.2.60.0200.01014.90
7.2.50.0790.01315.06
7.2.40.0120.00914.72
7.2.30.0090.01414.79
7.2.20.0130.00915.14
7.2.10.0380.00414.91
7.2.00.0190.00314.89
7.1.200.0000.00815.73
7.1.170.0110.00813.89
7.1.160.0160.00313.86
7.1.150.0130.00913.88
7.1.140.0140.00614.08
7.1.130.0130.00613.86
7.1.120.0090.00913.74
7.1.110.0140.00613.75
7.1.100.0170.01013.86
7.1.90.0160.00613.98
7.1.80.0150.00313.54
7.1.70.0170.01014.03
7.1.60.0420.01431.50
7.1.50.0270.01232.03
7.1.40.0280.01431.79
7.1.30.0270.01131.71
7.1.20.0230.01531.66
7.1.10.0090.00913.57
7.1.00.0060.01213.98

preferences:
68.96 ms | 401 KiB | 5 Q