3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { protected $roots = []; public function addCategory($category, $parent) { if ($this->categoryExists($this->roots, $category)) { throw new InvalidArgumentException(); } if ($parent === null) { $this->tree[$category] = []; } $node = $findNode($parent, $this->root); if(!isset($node)) { throw new InvalidArgumentException(); } $node[$category] = []; } public function getChildren($parent) { $node = $findNode($parent, $this->root); if(!isset($node)) { throw new InvalidArgumentException(); } return array_keys($node); } public function findNode($node, &$root) { if (in_array($node, array_keys($root))) { return $root[$node]; } foreach ($root as $n) { return $this->findNode($node, $n); } } public function categoryExists($nodes, $category) { $exists = false; foreach($nodes as $node) { if (in_array($category, $this->getChildren($node))) { return true; } $exists = $this->categoryExists($node, $category); } return $exists; } } // For testing purposes (do not submit uncommented): $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('C', 'A'); //echo implode(',', $c->getChildren('A'));

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.0070.00716.63
8.3.50.0070.01322.01
8.3.40.0090.00918.81
8.3.30.0070.00718.89
8.3.20.0040.00420.34
8.3.10.0080.00023.36
8.3.00.0040.00419.91
8.2.180.0130.00318.54
8.2.170.0070.00722.96
8.2.160.0070.00719.45
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00020.92
8.2.120.0040.00426.35
8.2.110.0000.00920.20
8.2.100.0090.00318.05
8.2.90.0040.00419.26
8.2.80.0040.00417.97
8.2.70.0070.00317.74
8.2.60.0040.00717.93
8.2.50.0030.00618.07
8.2.40.0060.00321.20
8.2.30.0050.00320.67
8.2.20.0000.00917.91
8.2.10.0050.00318.28
8.2.00.0040.00418.16
8.1.280.0100.01025.92
8.1.270.0090.00918.86
8.1.260.0080.00028.09
8.1.250.0000.00928.09
8.1.240.0030.00622.06
8.1.230.0080.00317.79
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0000.00818.55
8.1.160.0040.00420.70
8.1.150.0000.00818.94
8.1.140.0000.00819.68
8.1.130.0030.00317.79
8.1.120.0030.00517.53
8.1.110.0040.00417.51
8.1.100.0040.00417.38
8.1.90.0080.00017.41
8.1.80.0040.00417.46
8.1.70.0070.00017.46
8.1.60.0030.00617.62
8.1.50.0000.00817.54
8.1.40.0060.00317.53
8.1.30.0080.00017.64
8.1.20.0000.00717.73
8.1.10.0000.00817.52
8.1.00.0090.00017.53
8.0.300.0080.00018.77
8.0.290.0080.00016.63
8.0.280.0030.00318.41
8.0.270.0030.00317.29
8.0.260.0000.00717.30
8.0.250.0030.00317.06
8.0.240.0070.00017.07
8.0.230.0030.00317.04
8.0.220.0000.00716.93
8.0.210.0000.00716.86
8.0.200.0000.00616.94
8.0.190.0000.00817.09
8.0.180.0040.00416.91
8.0.170.0030.00617.04
8.0.160.0030.00516.91
8.0.150.0030.00716.95
8.0.140.0040.00416.96
8.0.130.0000.00613.43
8.0.120.0000.00816.99
8.0.110.0040.00417.01
8.0.100.0020.00516.95
8.0.90.0000.00716.98
8.0.80.0110.01417.02
8.0.70.0050.00217.06
8.0.60.0040.00416.87
8.0.50.0050.00217.02
8.0.30.0040.01217.12
8.0.20.0120.00817.43
8.0.10.0000.00817.03
8.0.00.0080.01016.93
7.4.330.0000.00516.83
7.4.320.0000.00716.54
7.4.300.0070.00016.65
7.4.290.0030.00316.63
7.4.280.0000.00816.68
7.4.270.0030.00316.66
7.4.260.0000.00916.67
7.4.250.0070.00016.61
7.4.240.0040.00316.63
7.4.230.0000.00816.75
7.4.220.0070.01116.51
7.4.210.0100.00316.74
7.4.200.0000.00716.54
7.4.160.0090.00616.50
7.4.150.0070.01017.40
7.4.140.0080.01417.86
7.4.130.0100.01016.59
7.4.120.0060.01216.63
7.4.110.0120.01216.72
7.4.100.0150.00816.54
7.4.90.0070.01116.57
7.4.80.0090.00919.39
7.4.70.0090.00916.55
7.4.60.0030.01316.55
7.4.50.0070.01016.43
7.4.40.0060.01616.75
7.4.30.0000.01716.53
7.4.00.0120.00514.76
7.3.330.0060.00013.38
7.3.320.0060.00013.46
7.3.310.0030.00316.53
7.3.300.0000.00716.46
7.3.290.0110.00316.45
7.3.280.0060.01116.40
7.3.270.0120.00617.40
7.3.260.0120.00616.34
7.3.250.0070.01216.56
7.3.240.0130.00816.38
7.3.230.0110.00816.52
7.3.210.0030.01316.65
7.3.200.0100.00616.37
7.3.190.0120.01216.69
7.3.180.0110.00716.51
7.3.170.0180.00016.42
7.3.160.0060.00916.63
7.3.120.0090.00914.57
7.3.110.0100.01014.79
7.3.100.0090.00614.98
7.3.90.0040.00814.63
7.3.80.0090.00614.93
7.3.70.0040.00714.92
7.3.60.0080.00814.66
7.3.50.0090.00314.67
7.3.40.0060.00314.59
7.3.30.0000.01114.91
7.3.20.0070.00716.60
7.3.10.0110.00416.85
7.3.00.0000.01316.76
7.2.330.0040.01316.77
7.2.320.0090.00916.79
7.2.310.0140.00316.80
7.2.300.0100.00716.44
7.2.290.0090.01216.82
7.2.250.0080.00814.83
7.2.240.0130.00715.21
7.2.230.0030.01015.08
7.2.220.0100.00715.35
7.2.210.0030.01514.99
7.2.200.0040.00715.16
7.2.190.0130.00315.08
7.2.180.0040.01115.08
7.2.170.0080.00415.17
7.2.160.0030.00615.27
7.2.150.0030.01416.68
7.2.140.0030.01116.95
7.2.130.0000.01316.96
7.2.120.0000.00917.12
7.2.110.0040.01116.87
7.2.100.0030.00617.00
7.2.90.0160.00017.02
7.2.80.0030.01016.76
7.2.70.0080.00316.76
7.2.60.0040.01216.84
7.2.50.0100.00716.90
7.2.40.0060.01016.94
7.2.30.0060.00617.09
7.2.20.0100.00617.06
7.2.10.0030.01417.14
7.2.00.0020.01018.21
7.1.330.0070.01015.81
7.1.320.0070.00715.85
7.1.310.0030.01415.77
7.1.300.0030.01015.61
7.1.290.0110.00415.81
7.1.280.0080.00416.03
7.1.270.0000.00915.74
7.1.260.0040.00415.65
7.1.250.0070.00715.62
7.1.240.0060.00615.63
7.1.230.0030.00915.86
7.1.220.0100.00315.68
7.1.210.0070.00715.97
7.1.200.0040.00815.80
7.1.190.0040.00715.84
7.1.180.0070.00715.87
7.1.170.0000.00915.79
7.1.160.0070.00415.79
7.1.150.0070.00715.74
7.1.140.0060.00315.60
7.1.130.0000.01415.62
7.1.120.0030.01316.02
7.1.110.0110.00015.80
7.1.100.0020.01017.07
7.1.90.0030.00515.96
7.1.80.0040.00415.95
7.1.70.0050.00816.58
7.1.60.0050.01217.58
7.1.50.0050.01216.48
7.1.40.0070.00715.68
7.1.30.0070.00715.78
7.1.20.0000.00815.92
7.1.10.0110.00015.85
7.1.00.0030.04419.09
7.0.330.0070.00715.43
7.0.320.0080.00615.38
7.0.310.0120.00315.37
7.0.300.0080.00815.46
7.0.290.0090.00615.45
7.0.280.0030.01015.65
7.0.270.0110.00415.48
7.0.260.0070.00715.34
7.0.250.0000.00815.46
7.0.240.0060.00315.63
7.0.230.0040.00415.38
7.0.220.0030.01215.59
7.0.210.0100.00715.32
7.0.200.0060.00416.04
7.0.190.0080.00015.45
7.0.180.0130.00015.55
7.0.170.0060.00615.64
7.0.160.0100.00315.25
7.0.150.0040.00815.60
7.0.140.0060.00615.53
7.0.130.0030.00915.19
7.0.120.0090.00015.49
7.0.110.0060.00615.38
7.0.100.0070.00615.51
7.0.90.0030.00715.53
7.0.80.0080.00515.10
7.0.70.0060.00615.24
7.0.60.0100.03317.73
7.0.50.0080.03816.69
7.0.40.0050.02316.78
7.0.30.0210.03816.72
7.0.20.0220.03816.88
7.0.10.0050.04716.86
7.0.00.0060.02516.86
5.6.400.0030.00714.77
5.6.390.0060.00914.66
5.6.380.0040.00514.81
5.6.370.0030.00714.45
5.6.360.0040.01214.45
5.6.350.0000.01114.45
5.6.340.0060.00614.44
5.6.330.0070.00714.13
5.6.320.0080.00614.48
5.6.310.0000.01514.31
5.6.300.0100.00014.57
5.6.290.0050.01114.41
5.6.280.0070.01817.77
5.6.270.0040.01014.25
5.6.260.0000.00914.65
5.6.250.0100.00014.51
5.6.240.0030.01214.42
5.6.230.0100.00714.51
5.6.220.0030.01014.75
5.6.210.0120.03317.43
5.6.200.0050.03216.38
5.6.190.0120.03717.51
5.6.180.0150.03117.64
5.6.170.0110.04317.43
5.6.160.0030.02617.41
5.6.150.0100.03316.17
5.6.140.0080.04316.28
5.6.130.0140.03216.44
5.6.120.0030.03017.76
5.6.110.0080.03717.86
5.6.100.0050.04717.84
5.6.90.0050.03817.71
5.6.80.0050.03417.45
5.6.70.0100.00614.51
5.6.60.0080.00814.47
5.6.50.0000.01614.66
5.6.40.0050.00514.36
5.6.30.0040.01114.36
5.6.20.0100.00314.48
5.6.10.0000.01214.27
5.6.00.0000.01314.29
5.5.380.0030.00714.35
5.5.370.0070.00714.29
5.5.360.0100.00314.76
5.5.350.0220.04017.48
5.5.340.0080.03216.35
5.5.330.0080.03717.25
5.5.320.0180.04017.21
5.5.310.0130.04517.19
5.5.300.0080.02816.31
5.5.290.0060.04616.22
5.5.280.0140.03817.46
5.5.270.0090.02017.67
5.5.260.0070.03517.60
5.5.250.0080.04417.40
5.5.240.0070.03317.26
5.5.230.0150.00014.44
5.5.220.0100.00314.42
5.5.210.0090.00314.45
5.5.200.0000.00814.49
5.5.190.0030.01014.41
5.5.180.0060.00614.17
5.5.170.0030.01014.55
5.5.160.0040.00414.26
5.5.150.0040.00414.43
5.5.140.0040.00714.29
5.5.130.0070.00414.46
5.5.120.0060.00914.61
5.5.110.0060.00914.41
5.5.100.0060.00614.48
5.5.90.0000.00914.23
5.5.80.0030.00714.48
5.5.70.0080.00514.37
5.5.60.0110.00014.40
5.5.50.0030.00914.50
5.5.40.0030.00914.40
5.5.30.0100.00314.43
5.5.20.0100.00313.96
5.5.10.0060.01214.15
5.5.00.0000.01514.28

preferences:
47.82 ms | 401 KiB | 5 Q