3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); header('Content-Type: text/plain; charset="utf-8"'); class NodeIterator extends \RecursiveArrayIterator { /** * @inheritdoc */ public function hasChildren() { return $this->current()->hasChildren(); } /** * @inheritdoc */ public function getChildren() { return new NodeIterator($this->current()->getChildren()); } } class Node implements \JsonSerializable, \IteratorAggregate { /** * @var mixed */ private $data; /** * @var Node[] */ private $children = []; /** * Node constructor. * * @param mixed $data */ public function __construct($data) { $this->data = $data; } /** * @return mixed */ public function getData() { return $this->data; } /** * @return bool */ public function hasChildren() { return count($this->children) > 0; } /** * @return \RecursiveArrayIterator */ public function getChildren() { return new \RecursiveArrayIterator($this->children); } /** * @param Node $child * * @return Node */ public function addChild(self $child) { if (in_array($child, $this->children, true)) { throw new \InvalidArgumentException('duplicate'); } $this->children[] = $child; return $child; } /** * @inheritdoc */ public function jsonSerialize() { return [ 'data' => $this->data, 'children' => $this->children ]; } /** * @inheritdoc */ public function getIterator() { return new NodeIterator([$this]); } } $root = new Node('root'); $root->addChild(new Node('sub1'))->addChild(new Node('sub1.1')); $root->addChild(new Node('sub2'))->addChild(new Node('sub2.1'))->addChild(new Node('sub.2.1.1')); $root->addChild(new Node('sub3')); print_r(json_encode($root, JSON_PRETTY_PRINT)); echo "\n\n"; foreach ($it = new RecursiveIteratorIterator(new NodeIterator([$root]), RecursiveIteratorIterator::SELF_FIRST) as $node) { echo str_repeat('.', $it->getDepth()), $node->getData(), "\n"; } echo "\n\n"; foreach ($it = new RecursiveIteratorIterator($root, RecursiveIteratorIterator::SELF_FIRST) as $node) { echo str_repeat('.', $it->getDepth()), $node->getData(), "\n"; }

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.4.120.0120.00924.45
8.4.110.0060.01120.54
8.4.100.0110.00717.88
8.4.90.0130.00818.79
8.4.80.0110.00919.56
8.4.70.0110.01017.98
8.4.60.0060.00920.70
8.4.50.0140.00619.61
8.4.40.0060.00319.41
8.4.30.0080.01119.54
8.4.20.0090.00020.58
8.4.10.0060.00319.84
8.3.250.0080.01218.80
8.3.240.0030.00517.41
8.3.230.0090.00116.73
8.3.220.0110.00817.35
8.3.210.0100.00518.76
8.3.200.0030.00616.97
8.3.190.0110.00917.47
8.3.180.0050.00516.68
8.3.170.0140.00417.35
8.3.160.0070.00316.82
8.3.150.0080.01118.93
8.3.140.0080.00016.96
8.3.130.0100.00018.42
8.3.120.0060.00320.73
8.3.110.0090.00320.94
8.3.100.0050.00524.06
8.3.90.0090.00016.60
8.3.80.0060.00317.97
8.3.70.0100.01016.88
8.3.60.0090.00918.68
8.3.50.0120.00722.17
8.3.40.0090.00618.79
8.3.30.0090.00918.82
8.3.20.0100.00622.15
8.3.10.0090.00021.91
8.3.00.0030.00521.02
8.2.290.0110.00722.24
8.2.280.0150.00420.20
8.2.270.0120.00917.54
8.2.260.0140.00318.93
8.2.250.0090.00017.04
8.2.240.0070.00417.28
8.2.230.0100.01322.58
8.2.220.0040.00437.54
8.2.210.0080.00026.77
8.2.200.0000.00916.88
8.2.190.0130.00716.88
8.2.180.0040.01516.50
8.2.170.0120.00622.96
8.2.160.0100.00620.35
8.2.150.0050.00525.66
8.2.140.0040.00424.66
8.2.130.0040.00421.05
8.2.120.0040.00426.35
8.2.110.0040.00721.11
8.2.100.0060.00617.91
8.2.90.0030.00520.47
8.2.80.0050.00318.02
8.2.70.0060.00317.93
8.2.60.0040.00418.09
8.2.50.0080.00018.10
8.2.40.0060.00320.61
8.2.30.0050.00319.25
8.2.20.0050.00218.16
8.2.10.0040.00418.16
8.2.00.0030.00517.68
8.1.330.0050.00521.88
8.1.320.0100.00916.49
8.1.310.0150.00416.50
8.1.300.0100.01019.80
8.1.290.0050.00518.88
8.1.280.0160.00325.92
8.1.270.0050.00322.22
8.1.260.0000.00728.09
8.1.250.0040.00428.09
8.1.240.0090.00022.66
8.1.230.0090.00320.97
8.1.220.0090.00017.74
8.1.210.0000.00819.02
8.1.200.0060.00317.35
8.1.190.0030.00517.23
8.1.180.0030.00518.10
8.1.170.0030.00518.50
8.1.160.0040.00418.93
8.1.150.0040.00420.21
8.1.140.0080.00019.73
8.1.130.0050.00217.48
8.1.120.0000.00717.55
8.1.110.0030.00617.34
8.1.100.0000.00717.46
8.1.90.0030.00617.56
8.1.80.0000.00717.54
8.1.70.0000.00717.48
8.1.60.0040.00417.52
8.1.50.0040.00417.50
8.1.40.0040.00417.56
8.1.30.0060.00317.65
8.1.20.0040.00417.73
8.1.10.0030.00917.61
8.1.00.0080.00017.62
8.0.300.0040.00419.95
8.0.290.0080.00016.88
8.0.280.0080.00018.41
8.0.270.0040.00717.02
8.0.260.0000.00716.96
8.0.250.0030.00317.09
8.0.240.0030.00317.13
8.0.230.0070.00016.95
8.0.220.0070.00016.93
8.0.210.0040.00416.99
8.0.200.0030.00317.05
8.0.190.0040.00417.07
8.0.180.0060.00316.90
8.0.170.0080.00017.09
8.0.160.0050.00217.09
8.0.150.0040.00416.97
8.0.140.0030.00616.95
8.0.130.0030.00313.41
8.0.120.0040.00416.92
8.0.110.0030.00516.87
8.0.100.0000.00716.88
8.0.90.0030.00517.01
8.0.80.0030.01316.98
8.0.70.0040.00417.06
8.0.60.0000.00817.02
8.0.50.0040.00416.87
8.0.30.0100.01117.05
8.0.20.0120.01017.40
8.0.10.0000.00817.06
8.0.00.0080.00916.73
7.4.330.0000.00615.55
7.4.320.0000.00816.59
7.4.300.0070.00016.65
7.4.290.0070.00016.55
7.4.280.0030.00716.63
7.4.270.0030.00316.60
7.4.260.0030.00316.46
7.4.250.0000.00716.65
7.4.240.0030.00516.63
7.4.230.0030.00316.66
7.4.220.0060.01316.55
7.4.210.0070.01016.44
7.4.200.0040.00416.74
7.4.160.0070.01216.49
7.4.150.0070.01117.40
7.4.140.0160.00317.86
7.4.130.0130.00716.56
7.4.120.0120.01016.59
7.4.110.0070.01116.52
7.4.100.0080.00816.63
7.4.90.0090.01016.38
7.4.80.0120.00619.39
7.4.70.0070.01016.53
7.4.60.0170.00316.51
7.4.50.0070.00716.41
7.4.40.0090.00916.47
7.4.30.0090.00916.47
7.4.20.0060.01016.38
7.4.10.0130.00916.53
7.4.00.0070.01015.64
7.3.330.0060.00013.20
7.3.320.0030.00313.37
7.3.310.0000.00816.40
7.3.300.0000.00716.30
7.3.290.0040.01416.33
7.3.280.0070.01116.34
7.3.270.0090.00917.40
7.3.260.0160.00516.29
7.3.250.0090.01116.51
7.3.240.0090.00916.46
7.3.230.0130.00516.39
7.3.210.0210.00316.40
7.3.200.0100.00716.47
7.3.190.0030.01416.36
7.3.180.0120.00916.55
7.3.170.0030.01316.61
7.3.160.0060.01216.39
7.3.150.0090.01216.33
7.3.140.0090.00916.28
7.3.130.0040.01216.42
7.3.120.0060.00916.53
7.3.110.0120.00316.56
7.3.100.0130.00316.19
7.3.90.0150.00616.36
7.3.80.0030.01015.76
7.3.70.0090.00615.53
7.3.60.0120.00515.53
7.3.50.0060.01215.43
7.3.40.0060.01115.68
7.3.30.0120.00615.52
7.3.20.0080.00616.57
7.3.10.0100.00516.57
7.3.00.0090.01116.58
7.2.330.0150.00316.68
7.2.320.0070.01016.71
7.2.310.0090.00916.63
7.2.300.0080.01816.85
7.2.290.0030.02016.90
7.2.280.0110.01116.47
7.2.270.0090.01216.93
7.2.260.0140.00316.72
7.2.250.0030.01316.43
7.2.240.0150.00916.64
7.2.230.0090.00916.87
7.2.220.0070.01416.60
7.2.210.0020.01315.67
7.2.200.0070.01015.89
7.2.190.0080.00615.83
7.2.180.0060.01115.92
7.2.170.0130.00315.82
7.2.160.0080.01215.89
7.2.150.0010.01416.72
7.2.140.0050.01116.84
7.2.130.0140.00816.77
7.2.120.0110.00716.75
7.2.110.0080.00716.59
7.2.100.0070.01016.76
7.2.90.0110.00316.87
7.2.80.0040.01116.81
7.2.70.0120.01016.94
7.2.60.0090.00916.84
7.2.50.0080.00816.88
7.2.40.0080.01316.77
7.2.30.0130.00716.98
7.2.20.0100.00516.87
7.2.10.0120.00716.79
7.2.00.0090.00916.91
7.1.330.0070.01415.55
7.1.320.0080.01515.75
7.1.310.0070.00715.67
7.1.300.0040.01015.70
7.1.290.0080.00915.76
7.1.280.0040.01015.68
7.1.270.0110.00315.62
7.1.260.0070.00615.59
7.1.250.0180.01015.62
7.1.240.0130.00415.55
7.1.230.0150.00515.67
7.1.220.0070.01415.44
7.1.210.0090.00915.63
7.1.200.0080.01015.68
7.1.190.0140.00715.51
7.1.180.0100.01115.55
7.1.170.0120.00715.62
7.1.160.0080.01415.57
7.1.150.0130.01015.60
7.1.140.0120.00915.62
7.1.130.0050.01115.56
7.1.120.0110.00815.73
7.1.110.0080.00915.74
7.1.100.0090.01115.71
7.1.90.0120.01015.78
7.1.80.0100.00915.58
7.1.70.0040.01216.04
7.1.60.1320.00916.19
7.1.50.0120.00715.82
7.1.40.0130.00815.76
7.1.30.0080.01015.72
7.1.20.0130.00715.76
7.1.10.0030.01515.69
7.1.00.0160.03017.83
7.0.330.0120.00615.42
7.0.320.0130.00715.30
7.0.310.0140.00915.33
7.0.300.0100.00815.43
7.0.290.0160.00615.41
7.0.280.0170.00515.30
7.0.270.0130.00715.34
7.0.260.0100.00715.37
7.0.250.0090.01215.35
7.0.240.0050.01015.38
7.0.230.0120.00915.22
7.0.220.0120.01115.34
7.0.210.0070.01215.45
7.0.200.0110.00715.83
7.0.190.0100.00815.42
7.0.180.0100.01015.40
7.0.170.0080.00915.49
7.0.160.0060.01315.44
7.0.150.0160.00315.29
7.0.140.0150.00815.46
7.0.130.0150.02917.57
7.0.120.0180.02117.54
7.0.110.0130.03317.57
7.0.100.0150.02517.04
7.0.90.0130.02917.10
7.0.80.0080.03216.99
7.0.70.0120.03116.99
7.0.60.0140.02616.92
7.0.50.0130.02517.06
7.0.40.0120.02617.14
7.0.30.0150.02716.42
7.0.20.0270.03316.44
7.0.10.0100.03316.43
7.0.00.0270.03116.48
5.6.400.0120.00815.31
5.6.390.0120.00615.49
5.6.380.0120.01015.42
5.6.370.0160.00815.40
5.6.360.0110.01015.42
5.6.350.0160.00715.49
5.6.340.0130.01015.33
5.6.330.0100.01015.27
5.6.320.0110.01215.44
5.6.310.0120.01115.35
5.6.300.0090.01515.52
5.6.290.0100.01315.48
5.6.280.0130.02817.18
5.6.270.0120.02917.26
5.6.260.0230.02217.25
5.6.250.0160.02217.27
5.6.240.0110.02917.21
5.6.230.0160.02517.31
5.6.220.0090.03517.13
5.6.210.0100.03417.29
5.6.200.0110.02617.21
5.6.190.0130.03017.19
5.6.180.0140.02617.33
5.6.170.0150.03217.23
5.6.160.0150.03317.12
5.6.150.0120.03217.31
5.6.140.0080.02717.28
5.6.130.0100.02617.09
5.6.120.0080.02917.24
5.6.110.0090.02717.14
5.6.100.0170.02917.08
5.6.90.0130.02817.14
5.6.80.0090.03316.97
5.6.70.0090.02816.93
5.6.60.0150.02516.89
5.6.50.0120.02317.03
5.6.40.0130.02416.92
5.6.30.0140.03016.87
5.6.20.0170.02717.00
5.6.10.0110.03216.90
5.6.00.0100.03316.94
5.3.100.0060.00812.84

preferences:
30.29 ms | 403 KiB | 5 Q