3v4l.org

run code in 300+ PHP versions simultaneously
<?php $context = [ 'mes' => [ 'attributes' => [ 't' => 'AddEvent', 'id' => 'test_id', ], 'ev' => [ 'attributes' => [ 'evt' => 'packet20130828ki3si0', 'src' => 'NVV', 'st' => 'test', 'start' => '12423511247', 'stop' => '12423991978', 'addrtype' => 'MB', 'clntID' => '+380957700418', 'lg' => '', 'bank' => '', 'lang' => '', 'prior' => '', 'brnm' => '', 'extref' => '', 'intref' => '', 'extaddrtype' => '', 'extaddrid' => '', 'recall' => '', ], 'attr' => [ [ 'attributes' => [ 'code' => '1', 'val' => '11', ], ], [ 'attributes' => [ 'code' => '2', 'val' => '12', ], ], ], 'hist' => [ [ 'attributes' => [ 'st' => '', 'ch' => '', 'lg' => '', 'con' => '', 'com' => '', 'addrtype' => '', 'addrid' => '', 'dt' => '', 'contactId' => '', ], ], ], ], ], ]; class Conv { protected $res; protected $context; public function __construct(array $context) { if (count($context) != 1) { throw new Exception('Must be only one root element', 500); } $this->context = $context; $this->init(key($this->context)); } public function conv() { return $this->a2x(current($this->context), $this->res)->asXML(); } protected function init($root) { $this->res = new SimpleXMLElement("<{$root}/>"); } protected function addAttribs(array $attribs, SimpleXMLElement $node) { if (count($attribs)) { foreach ($attribs as $attrKey => $attrVal) { $node->addAttribute($attrKey, $attrVal); } } return $node; } protected function tryToAddAttribs(array $inner, SimpleXMLElement $node) { if (isset($inner['attributes'])) { $this->addAttribs($inner['attributes'], $node); unset($inner['attributes']); } return $node; } protected function addEnum(array $items, SimpleXMLElement $node, $caption) { $this->dump('adding enum', ['caption'=>$caption,'items'=>$items]); if (count($items)) { foreach ($items as $item) { $subNode = $node->addChild($caption); $this->tryToAddAttribs($item, $subNode); unset($item['attributes']); } } } protected function a2x(array $inner, SimpleXMLElement $node) { $this->tryToAddAttribs($inner, $node); unset($inner['attributes']); if (count($inner)) { foreach ($inner as $key => $value) { $this->dump('cur', ['key'=>$key,'val'=>$value]); if ($this->isEnumeration($value)) { $this->dump('is enum', $value); $this->addEnum($value, $node, $key); } else { $this->dump('is NOT enum', $value); $subNode = $node->addChild($key); $this->a2x($value, $subNode); } } } return $this->res; } protected function isEnumeration(array $items) { $keys = array_keys($items); foreach ($keys as $key) { if (!is_numeric($key)) { return false; } } return true; } protected function dump($title, $var) { if (false) { echo $title . ': ', json_encode($var) . '<hr/>'; } } } $a2x = new Conv($context); var_dump($a2x->conv());

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.0090.00617.00
8.3.60.0070.01417.13
8.3.50.0090.00617.68
8.3.40.0120.00919.30
8.3.30.0120.00619.21
8.3.20.0080.00019.15
8.3.10.0060.00320.81
8.3.00.0040.00419.51
8.2.180.0120.00817.00
8.2.170.0120.00622.96
8.2.160.0090.00621.07
8.2.150.0000.00824.18
8.2.140.0030.00624.66
8.2.130.0040.00426.16
8.2.120.0030.00620.77
8.2.110.0090.00019.58
8.2.100.0140.00018.16
8.2.90.0000.00918.00
8.2.80.0080.00019.17
8.2.70.0040.00418.13
8.2.60.0030.00518.00
8.2.50.0000.00817.88
8.2.40.0080.00019.59
8.2.30.0030.00619.60
8.2.20.0030.00619.71
8.2.10.0040.00418.15
8.2.00.0070.00418.19
8.1.280.0070.00725.92
8.1.270.0070.00724.66
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0040.00719.27
8.1.230.0080.00421.35
8.1.220.0060.00319.09
8.1.210.0040.00418.77
8.1.200.0040.00417.50
8.1.190.0060.00317.72
8.1.180.0030.00618.10
8.1.170.0040.00417.73
8.1.160.0040.00419.16
8.1.150.0000.00719.18
8.1.140.0000.00717.82
8.1.130.0040.00418.17
8.1.120.0030.00617.66
8.1.110.0030.00517.79
8.1.100.0030.00417.76
8.1.90.0000.00717.65
8.1.80.0040.00417.76
8.1.70.0000.00717.74
8.1.60.0030.00517.91
8.1.50.0000.00817.77
8.1.40.0000.00817.84
8.1.30.0030.00517.88
8.1.20.0030.00517.84
8.1.10.0040.00417.78
8.1.00.0050.00317.72
8.0.300.0040.00418.77
8.0.290.0040.00417.13
8.0.280.0000.00718.74
8.0.270.0040.00417.20
8.0.260.0000.00717.15
8.0.250.0040.00417.36
8.0.240.0040.00417.21
8.0.230.0030.00317.38
8.0.220.0070.00017.30
8.0.210.0000.00717.15
8.0.200.0000.00617.40
8.0.190.0000.00817.40
8.0.180.0070.00017.32
8.0.170.0040.00417.32
8.0.160.0040.00417.25
8.0.150.0060.00317.25
8.0.140.0100.00017.05
8.0.130.0030.00313.67
8.0.120.0050.00317.10
8.0.110.0040.00417.30
8.0.100.0040.00417.30
8.0.90.0060.00317.19
8.0.80.0070.01017.29
8.0.70.0070.00017.21
8.0.60.0000.00717.05
8.0.50.0000.00717.30
8.0.30.0180.00017.38
8.0.20.0120.00617.36
8.0.10.0040.00417.32
8.0.00.0080.01117.38
7.4.330.0020.00213.29
7.4.320.0030.00316.86
7.4.300.0030.00316.79
7.4.290.0030.00316.93
7.4.280.0050.00316.92
7.4.270.0040.00416.91
7.4.260.0000.00613.63
7.4.250.0060.00316.91
7.4.240.0040.00316.73
7.4.230.0040.00416.90
7.4.220.0100.01016.90
7.4.210.0060.01016.97
7.4.200.0030.00316.92
7.4.190.0040.00416.94
7.4.160.0030.01316.89
7.4.150.0030.02316.67
7.4.140.0140.00316.70
7.4.130.0070.01116.97
7.4.120.0070.01016.83
7.4.110.0060.01217.02
7.4.100.0160.00016.95
7.4.90.0070.01716.79
7.4.80.0090.00916.66
7.4.70.0110.00716.89
7.4.60.0100.00716.91
7.4.50.0030.00316.92
7.4.40.0100.00716.88
7.4.30.0060.00916.84
7.4.00.0080.01115.16
7.3.330.0000.00713.72
7.3.320.0060.00013.62
7.3.310.0040.00416.54
7.3.300.0040.00416.77
7.3.290.0080.00816.71
7.3.280.0090.01216.77
7.3.270.0040.01416.70
7.3.260.0070.01016.84
7.3.250.0110.01016.93
7.3.240.0030.01316.94
7.3.230.0090.00916.79
7.3.210.0070.01116.81
7.3.200.0060.01119.39
7.3.190.0100.01316.95
7.3.180.0060.00916.74
7.3.170.0110.00616.91
7.3.160.0030.01416.79
7.3.120.0060.01215.09
7.3.110.0070.01215.17
7.3.100.0040.01215.14
7.3.90.0050.00815.00
7.3.80.0040.01015.14
7.3.70.0080.00715.02
7.3.60.0060.01014.99
7.3.50.0080.00915.03
7.3.40.0070.00714.93
7.3.30.0070.00615.08
7.3.20.0080.00716.73
7.3.10.0090.00816.79
7.3.00.0040.00516.89
7.2.330.0100.01016.88
7.2.320.0100.01317.18
7.2.310.0060.01217.14
7.2.300.0090.00917.05
7.2.290.0110.00716.78
7.2.250.0070.00915.17
7.2.240.0050.01515.33
7.2.230.0080.00815.26
7.2.220.0090.00415.04
7.2.210.0030.01115.33
7.2.200.0070.00515.24
7.2.190.0020.01415.27
7.2.180.0080.00715.36
7.2.170.0040.00715.22
7.2.130.0080.00616.63
7.2.120.0040.00716.98
7.2.110.0090.00616.69
7.2.100.0090.00616.89
7.2.90.0000.00916.69
7.2.80.0100.00616.81
7.2.70.0040.00716.76
7.2.60.0000.01517.03
7.2.50.0030.01316.75
7.2.40.0090.00616.89
7.2.30.0100.00616.82
7.2.20.0030.01317.01
7.2.10.0030.01116.76
7.2.00.0030.01218.36
7.1.330.0070.00715.96
7.1.320.0060.00315.80
7.1.310.0070.00715.99
7.1.300.0030.01515.92
7.1.290.0100.00815.85
7.1.280.0060.00815.83
7.1.270.0030.00915.89
7.1.260.0050.00715.94
7.1.250.0000.00915.82
7.1.100.0030.00918.42
7.1.70.0070.01017.39
7.1.60.0030.01319.31
7.1.50.0000.01417.20
7.1.00.0030.04722.42
7.0.200.0100.00516.84
7.0.140.0070.07322.15
7.0.90.0670.08020.26
7.0.80.0500.04020.21
7.0.70.0600.08320.27
7.0.60.0530.07320.14
7.0.50.0530.06020.45
7.0.40.0100.03720.28
7.0.30.0030.04720.16
7.0.20.0070.09020.15
7.0.10.0100.05020.27
7.0.00.0200.07020.14
5.6.280.0100.06321.10
5.6.240.0130.07720.97
5.6.230.0200.06320.75
5.6.220.0070.08720.85
5.6.210.0030.04720.84
5.6.200.0100.08021.07
5.6.190.0100.08021.17
5.6.180.0030.05321.26
5.6.170.0070.07721.13
5.6.160.0100.06721.27
5.6.150.0070.07021.11
5.6.140.0000.08721.22
5.6.130.0100.09021.18
5.6.120.0070.08721.27
5.6.110.0070.08321.23
5.6.100.0130.05021.26
5.6.90.0030.06021.21
5.6.80.0070.04320.61
5.6.70.0100.04020.61
5.6.60.0100.03720.68
5.6.50.0100.06320.61
5.6.40.0070.08320.41
5.6.30.0070.06320.41
5.6.20.0070.08320.68
5.6.10.0070.08320.53
5.6.00.0070.06020.60
5.5.380.0030.08720.66
5.5.370.0170.06720.60
5.5.360.0130.06720.57
5.5.350.0070.08020.54
5.5.340.0100.07721.00
5.5.330.0030.06020.98
5.5.320.0030.08321.05
5.5.310.0000.08720.91
5.5.300.0030.08020.93
5.5.290.0100.04721.09
5.5.280.0070.08321.08
5.5.270.0030.08720.95
5.5.260.0030.08720.85
5.5.250.0100.07320.74
5.5.240.0100.07020.44
5.5.230.0070.07320.30
5.5.220.0130.03720.20
5.5.210.0070.07720.39
5.5.200.0070.06320.43
5.5.190.0070.07720.21
5.5.180.0030.05720.41
5.5.160.0070.04720.18
5.5.150.0070.05720.42
5.5.140.0100.03720.33
5.5.130.0070.07020.30
5.5.120.0000.06320.37
5.5.110.0070.07320.34
5.5.100.0170.06320.31
5.5.90.0130.06320.09
5.5.80.0100.07020.14
5.5.70.0030.07720.28
5.5.60.0070.06320.29
5.5.50.0100.08020.13
5.5.40.0130.06720.15
5.5.30.0000.08320.24
5.5.20.0100.04320.14
5.5.10.0100.07720.30
5.5.00.0100.07320.14
5.4.450.0030.05319.44
5.4.440.0030.07019.25
5.4.430.0000.08019.43
5.4.420.0100.06719.25
5.4.410.0000.08019.22
5.4.400.0170.05719.24
5.4.390.0070.04319.11
5.4.380.0030.04319.29
5.4.370.0130.06319.38
5.4.360.0170.06319.27
5.4.350.0130.07019.25
5.4.340.0030.08018.96
5.4.320.0070.08019.17
5.4.310.0100.07719.23
5.4.300.0030.08019.25
5.4.290.0070.05719.37
5.4.280.0100.08019.26
5.4.270.0070.06019.13
5.4.260.0170.06319.26
5.4.250.0100.07718.94
5.4.240.0130.06719.23
5.4.230.0100.07319.23
5.4.220.0030.04718.95
5.4.210.0000.06019.28
5.4.200.0070.07319.23
5.4.190.0030.04719.10
5.4.180.0070.06718.94
5.4.170.0100.07019.22
5.4.160.0100.07319.09
5.4.150.0070.07319.25
5.4.140.0000.04316.51
5.4.130.0000.05716.49
5.4.120.0000.06316.45
5.4.110.0030.05716.58
5.4.100.0100.06716.66
5.4.90.0030.04716.56
5.4.80.0130.07016.41
5.4.70.0130.05716.50
5.4.60.0070.06316.54
5.4.50.0030.04016.44
5.4.40.0170.05716.66
5.4.30.0130.05716.57
5.4.20.0070.06716.55
5.4.10.0130.04716.64
5.4.00.0070.07016.04
5.3.290.0070.05714.61
5.3.280.0070.05314.55
5.3.270.0030.08314.62
5.3.260.0070.06714.46
5.3.250.0130.07314.60
5.3.240.0070.07014.48
5.3.230.0070.07014.57
5.3.220.0130.03714.43
5.3.210.0070.07714.39
5.3.200.0070.04014.53
5.3.190.0170.04014.54
5.3.180.0030.05014.52
5.3.170.0000.07314.55
5.3.160.0070.06014.50
5.3.150.0070.06014.43
5.3.140.0100.03314.47
5.3.130.0070.06714.41
5.3.120.0100.06714.49
5.3.110.0100.07714.53
5.3.100.0100.05014.00
5.3.90.0030.04713.97
5.3.80.0100.07013.96
5.3.70.0070.07013.98
5.3.60.0070.04313.98
5.3.50.0030.07313.85
5.3.40.0030.05313.93
5.3.30.0070.04313.79
5.3.20.0030.07713.67
5.3.10.0030.06313.62
5.3.00.0130.06313.49
5.2.170.0030.06011.01
5.2.160.0030.06311.18
5.2.150.0070.05011.10
5.2.140.0070.06011.15
5.2.130.0030.05710.96
5.2.120.0200.04310.93
5.2.110.0130.05010.96
5.2.100.0070.06010.94
5.2.90.0070.06310.93
5.2.80.0130.02710.94
5.2.70.0100.03310.92
5.2.60.0070.06011.09
5.2.50.0070.05710.86
5.2.40.0030.04310.98
5.2.30.0030.06710.81
5.2.20.0130.04011.04
5.2.10.0030.06010.77
5.2.00.0000.06010.73
5.1.60.0070.05010.00
5.1.50.0030.05710.03
5.1.40.0070.0509.98
5.1.30.0030.04710.39
5.1.20.0070.05310.21
5.1.10.0070.05710.09
5.1.00.0100.05310.14
5.0.50.0070.0408.58
5.0.40.0030.0408.43
5.0.30.0070.0578.25
5.0.20.0000.0308.28
5.0.10.0100.0378.17
5.0.00.0070.0608.14
4.4.90.0030.0307.24
4.4.80.0000.0237.24
4.4.70.0030.0337.24
4.4.60.0000.0337.24
4.4.50.0030.0307.24
4.4.40.0030.0507.24
4.4.30.0030.0377.24
4.4.20.0000.0377.24
4.4.10.0030.0337.24
4.4.00.0000.0477.24
4.3.110.0000.0377.24
4.3.100.0070.0177.24
4.3.90.0030.0337.24
4.3.80.0030.0377.24
4.3.70.0070.0307.24
4.3.60.0070.0307.24
4.3.50.0000.0337.24
4.3.40.0000.0577.24
4.3.30.0000.0307.24
4.3.20.0000.0377.24
4.3.10.0030.0337.24
4.3.00.0070.0307.24

preferences:
41.19 ms | 401 KiB | 5 Q