3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Task 2: Parse the string * * Parse the $input string and build object tree that represents this structure: * https://drive.google.com/file/d/0BwhWcFzxN6_mZ2hkQlhZTnRrMDA/view?usp=sharing * Use Node class to build the tree and dump it to output * * Realize Node::dump() function and use it to output the tree in format: * A * B * C * C * C * B * C * C * A * B * B * C */ $input = 'A(B(CCC)(BB)(CC))A(BB(C))'; class Node { public $letter; private $items = []; public function __construct($letter) { $this->letter = $letter; } public function addItem($item) { $this->items[] = $item; } public function dump($level = 0) { if($level != 0){ echo str_repeat(" ", $level). $this->letter. PHP_EOL; } foreach($this->items as $item){ $item->dump($level + 1); } } } function parseInput($node, $input){ $letter = $input[0]; $explInput = explode($letter, $input); foreach($explInput as $key=>$chunk){ if($key == 0){continue;} if(!empty($chunk)){ $chunk = preg_replace('/\((.*)\)/', '$1', $chunk); $chldNode = new Node($letter); $node->addItem($chldNode); parseInput($chldNode, $chunk); } else{ $node->addItem(new Node($letter)); } } } $root = new Node("R"); parseInput($root, $input); $root->dump();

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.0230.00016.88
8.3.50.0140.00018.39
8.3.40.0070.00719.09
8.3.30.0130.00318.96
8.3.20.0070.00021.86
8.3.10.0040.00423.48
8.3.00.0080.00019.68
8.2.180.0140.00418.54
8.2.170.0110.00422.96
8.2.160.0170.00019.50
8.2.150.0000.00824.18
8.2.140.0050.00224.66
8.2.130.0040.00420.38
8.2.120.0000.00826.35
8.2.110.0050.00519.39
8.2.100.0090.00317.97
8.2.90.0060.00319.01
8.2.80.0000.00917.97
8.2.70.0050.00317.88
8.2.60.0050.00318.05
8.2.50.0050.00318.10
8.2.40.0060.00320.43
8.2.30.0040.00419.36
8.2.20.0000.00818.16
8.2.10.0070.00018.23
8.2.00.0050.00218.27
8.1.280.0070.01125.92
8.1.270.0080.00020.83
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0090.00021.43
8.1.230.0040.00717.89
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.47
8.1.190.0060.00317.48
8.1.180.0080.00018.10
8.1.170.0040.00418.90
8.1.160.0040.00419.01
8.1.150.0050.00219.02
8.1.140.0040.00419.56
8.1.130.0030.00318.90
8.1.120.0000.00717.70
8.1.110.0030.00517.70
8.1.100.0070.00017.65
8.1.90.0040.00417.57
8.1.80.0050.00217.55
8.1.70.0070.00017.64
8.1.60.0000.00817.69
8.1.50.0080.00017.61
8.1.40.0080.00017.74
8.1.30.0000.00817.92
8.1.20.0040.00417.73
8.1.10.0000.00917.80
8.1.00.0000.00717.67
8.0.300.0070.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00718.52
8.0.270.0040.00416.95
8.0.260.0060.00018.52
8.0.250.0000.00717.15
8.0.240.0000.00817.17
8.0.230.0040.00417.19
8.0.220.0000.00716.98
8.0.210.0040.00417.00
8.0.200.0030.00317.16
8.0.190.0030.00617.18
8.0.180.0000.01017.14
8.0.170.0040.00417.13
8.0.160.0040.00417.14
8.0.150.0040.00416.94
8.0.140.0000.00716.93
8.0.130.0060.00013.50
8.0.120.0000.00817.05
8.0.110.0040.00417.04
8.0.100.0080.00016.91
8.0.90.0000.00717.11
8.0.80.0120.00317.00
8.0.70.0000.00816.96
8.0.60.0040.00417.01
8.0.50.0000.00817.11
8.0.30.0100.00917.39
8.0.20.0100.00917.43
8.0.10.0070.00016.99
8.0.00.0060.01217.23
7.4.330.0030.00315.55
7.4.320.0020.00516.66
7.4.300.0060.00316.86
7.4.290.0070.00016.75
7.4.280.0000.00716.75
7.4.270.0000.00816.78
7.4.260.0040.00416.64
7.4.250.0040.00416.80
7.4.240.0030.00516.91
7.4.230.0030.00316.62
7.4.220.0090.00916.89
7.4.210.0130.00416.83
7.4.200.0000.00716.66
7.4.160.0120.00916.68
7.4.150.0130.00317.40
7.4.140.0120.00817.86
7.4.130.0140.01016.73
7.4.120.0070.01216.77
7.4.110.0170.00016.76
7.4.100.0090.00916.74
7.4.90.0070.01116.63
7.4.80.0110.00719.39
7.4.70.0150.00316.64
7.4.60.0090.00916.57
7.4.50.0040.01116.61
7.4.40.0070.01016.74
7.4.30.0110.00816.64
7.4.00.0000.01314.91
7.3.330.0050.00013.32
7.3.320.0030.00313.55
7.3.310.0030.00316.55
7.3.300.0000.00716.56
7.3.290.0060.00916.50
7.3.280.0100.00816.47
7.3.270.0060.01217.40
7.3.260.0120.00416.60
7.3.250.0140.00516.73
7.3.240.0100.00816.73
7.3.230.0100.00716.77
7.3.210.0100.01016.70
7.3.200.0060.01016.90
7.3.190.0110.01016.57
7.3.180.0040.01116.57
7.3.170.0040.01216.97
7.3.160.0100.01016.78
7.3.120.0080.00615.24
7.3.110.0040.00914.87
7.3.100.0130.00314.82
7.3.90.0040.01215.27
7.3.80.0110.00315.19
7.3.70.0060.00915.15
7.3.60.0140.00314.94
7.3.50.0110.00415.07
7.3.40.0050.00514.98
7.3.30.0040.01414.75
7.3.20.0030.01416.95
7.3.10.0070.00716.88
7.3.00.0040.01116.93
7.2.330.0090.00916.89
7.2.320.0170.00716.90
7.2.310.0000.01816.92
7.2.300.0140.00417.02
7.2.290.0130.01016.84
7.2.240.0040.00815.44
7.2.230.0090.00615.33
7.2.220.0070.00715.36
7.2.210.0100.00615.03
7.2.200.0060.00615.33
7.2.190.0090.00615.39
7.2.180.0060.01015.32
7.2.170.0090.00615.45
7.2.160.0110.00415.23
7.2.150.0030.01416.85
7.2.140.0100.00717.19
7.2.130.0110.00517.07
7.2.120.0080.00816.97
7.2.110.0030.01117.16
7.2.100.0090.00616.97
7.2.90.0100.00717.06
7.2.80.0060.00817.13
7.2.70.0030.01017.01
7.2.60.0090.00717.12
7.2.50.0040.00917.24
7.2.40.0060.00817.05
7.2.30.0030.01317.14
7.2.20.0100.00317.14
7.2.10.0050.00917.19
7.2.00.0060.00918.02
7.1.330.0000.01316.03
7.1.320.0000.01315.97
7.1.310.0100.00316.12
7.1.300.0070.00715.96
7.1.290.0030.01515.88
7.1.280.0060.00916.02
7.1.270.0060.01216.16
7.1.260.0030.00915.98
7.1.250.0080.00515.88
7.1.200.0000.01215.96
7.1.100.0030.00718.27
7.1.70.0040.00417.52
7.1.60.0140.01015.38
7.1.50.0170.01035.16
7.1.40.0170.01034.59
7.1.30.0730.01334.68
7.1.20.0130.02034.57
7.1.10.0030.01016.80
7.1.00.0000.01716.84
7.0.200.0070.00717.01
7.0.190.0570.00714.77
7.0.180.0070.01016.28
7.0.170.0630.01016.32
7.0.160.0830.01014.57
7.0.150.0000.01316.08
7.0.140.0070.00716.39
7.0.130.0400.01314.98
7.0.120.0500.00716.57
7.0.110.0570.01014.65
7.0.100.0470.00714.66
7.0.90.0000.01016.62
7.0.80.0000.01316.61
7.0.70.0470.00314.54
7.0.60.0130.00016.05
7.0.50.0000.01016.60
7.0.40.0030.01016.55
7.0.30.0000.01016.59
7.0.20.0030.00716.66
7.0.10.0030.00716.63
7.0.00.0000.01716.53

preferences:
69.16 ms | 401 KiB | 5 Q