3v4l.org

run code in 300+ PHP versions simultaneously
<?php $context = [ 'mes' => [ 'attributes' => [ 't' => 'AddEvent', 'id' => 'test_id', 'text' => 'русский текст' ], '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; protected $charset; public function __construct(array $context, $charset = 'UTF-8') { if (count($context) != 1) { throw new Exception('Must be only one root element', 500); } $this->context = $context; $this->charset = $charset; $this->init(key($this->context)); } public function conv() { return $this->format($this->a2x(current($this->context), $this->res)); } protected function init($root) { $header = "<?xml version=\"1.0\" encoding=\"{$this->charset}\"?><{$root}/>"; $this->res = new SimpleXMLElement($header); } 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 formatXml(SimpleXMLElement $xml) { $dom = new DOMDocument("1.0"); $dom->formatOutput = true; return $dom->loadXML($xml->asXML())->saveXML(); } 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.60.0100.01017.13
8.3.50.0140.00516.88
8.3.40.0070.00719.00
8.3.30.0040.01219.04
8.3.20.0090.00018.82
8.3.10.0040.00420.68
8.3.00.0060.00319.50
8.2.180.0060.01317.25
8.2.170.0110.01122.96
8.2.160.0100.00321.45
8.2.150.0040.00424.18
8.2.140.0000.01124.66
8.2.130.0040.00426.16
8.2.120.0000.00819.61
8.2.110.0090.00021.12
8.2.100.0120.00018.16
8.2.90.0080.00019.59
8.2.80.0050.00219.46
8.2.70.0030.00617.71
8.2.60.0040.00418.29
8.2.50.0000.00818.07
8.2.40.0040.00418.28
8.2.30.0080.00018.19
8.2.20.0000.00817.91
8.2.10.0030.00618.06
8.2.00.0040.00717.98
8.1.280.0030.01425.92
8.1.270.0040.00424.66
8.1.260.0090.00026.35
8.1.250.0070.00028.09
8.1.240.0030.00622.59
8.1.230.0000.01120.99
8.1.220.0050.00318.04
8.1.210.0100.00318.94
8.1.200.0030.00617.36
8.1.190.0000.00817.78
8.1.180.0030.00618.10
8.1.170.0040.00419.05
8.1.160.0070.00019.06
8.1.150.0060.00318.86
8.1.140.0040.00417.70
8.1.130.0000.00717.97
8.1.120.0000.00717.74
8.1.110.0030.00617.77
8.1.100.0000.00817.73
8.1.90.0040.00417.65
8.1.80.0080.00017.60
8.1.70.0000.00717.68
8.1.60.0030.00617.71
8.1.50.0000.00917.60
8.1.40.0080.00017.77
8.1.30.0060.00317.82
8.1.20.0000.00817.98
8.1.10.0090.00017.72
8.1.00.0040.00417.77
8.0.300.0000.00720.27
8.0.290.0040.00417.13
8.0.280.0000.00718.61
8.0.270.0070.00017.51
8.0.260.0000.00717.12
8.0.250.0000.00917.19
8.0.240.0050.00317.30
8.0.230.0040.00417.11
8.0.220.0070.00017.20
8.0.210.0000.00717.07
8.0.200.0030.00317.12
8.0.190.0000.00817.33
8.0.180.0000.00917.12
8.0.170.0090.00017.23
8.0.160.0070.00017.26
8.0.150.0040.00417.04
8.0.140.0050.00517.02
8.0.130.0000.00813.59
8.0.120.0060.00317.02
8.0.110.0050.00217.15
8.0.100.0070.00017.11
8.0.90.0050.00217.23
8.0.80.0080.00817.07
8.0.70.0040.00417.07
8.0.60.0070.00017.21
8.0.50.0000.00817.15
8.0.30.0090.01017.22
8.0.20.0200.01417.23
8.0.10.0030.00517.36
8.0.00.0090.01117.17
7.4.330.0050.00013.20
7.4.320.0030.00316.68
7.4.300.0000.00616.76
7.4.290.0030.00316.75
7.4.280.0040.00416.76
7.4.270.0000.00716.88
7.4.260.0000.00513.46
7.4.250.0030.00616.77
7.4.240.0040.00416.79
7.4.230.0050.00316.61
7.4.220.0130.01216.80
7.4.210.0090.00716.83
7.4.200.0050.00316.95
7.4.190.0070.00016.98
7.4.160.0100.00716.91
7.4.150.0150.00316.76
7.4.140.0110.00916.74
7.4.130.0090.00816.64
7.4.120.0100.00716.67
7.4.110.0130.00316.77
7.4.100.0110.00816.73
7.4.90.0070.01716.81
7.4.80.0090.00919.39
7.4.70.0120.00416.63
7.4.60.0080.01116.73
7.4.50.0030.00616.55
7.4.40.0070.00716.75
7.4.30.0070.01016.78
7.4.00.0060.00815.15
7.3.330.0030.00313.64
7.3.320.0000.00613.67
7.3.310.0030.00316.63
7.3.300.0030.00316.55
7.3.290.0060.00916.61
7.3.280.0060.01216.65
7.3.270.0130.00616.89
7.3.260.0100.00716.60
7.3.250.0100.00816.74
7.3.240.0040.01316.84
7.3.230.0040.01316.64
7.3.210.0060.01316.75
7.3.200.0100.00716.76
7.3.190.0060.01216.70
7.3.180.0100.00616.75
7.3.170.0060.01016.64
7.3.160.0030.01316.57
7.3.120.0100.00515.08
7.3.110.0120.00614.88
7.3.100.0030.01115.21
7.3.90.0060.00314.99
7.3.80.0070.00715.05
7.3.70.0000.00914.88
7.3.60.0060.00914.85
7.3.50.0000.01114.97
7.3.40.0100.00315.05
7.3.30.0060.00315.08
7.3.20.0080.00416.69
7.3.10.0060.00916.90
7.3.00.0100.00316.76
7.2.330.0040.01416.71
7.2.320.0130.01016.62
7.2.310.0110.01117.06
7.2.300.0070.01016.90
7.2.290.0030.01317.03
7.2.250.0060.01315.49
7.2.240.0120.00814.98
7.2.230.0090.00615.31
7.2.220.0060.00615.08
7.2.210.0090.00315.25
7.2.200.0070.00715.28
7.2.190.0030.01215.15
7.2.180.0030.01015.37
7.2.170.0030.00915.13
7.2.60.0090.00617.00
7.2.00.0000.00919.67
7.1.330.0090.00315.89
7.1.320.0060.00616.13
7.1.310.0090.00316.02
7.1.300.0060.00315.64
7.1.290.0030.01015.66
7.1.280.0040.01115.94
7.1.270.0040.00415.96
7.1.260.0030.00715.98
7.1.200.0090.00315.95
7.1.100.0000.01318.33
7.1.70.0030.00717.30
7.1.60.0070.01419.40
7.1.50.0090.01517.08
7.1.00.0000.07022.55
7.0.200.0000.00716.90
7.0.140.0030.07022.12
7.0.120.0000.07722.10
7.0.90.0200.06720.01
7.0.80.0730.06720.00
7.0.70.0530.07720.25
7.0.60.0430.07020.19
7.0.50.0570.03720.56
7.0.40.0030.05720.19
7.0.30.0070.04720.14
7.0.20.0130.07720.27
7.0.10.0070.05020.03
7.0.00.0170.05720.04
5.6.280.0030.07321.23
5.6.240.0100.06020.84
5.6.230.0100.07320.71
5.6.220.0130.06720.80
5.6.210.0030.08720.60
5.6.200.0170.05321.12
5.6.190.0130.05021.12
5.6.180.0070.04321.19
5.6.170.0130.08321.16
5.6.160.0070.05021.17
5.6.150.0070.07721.29
5.6.140.0170.07321.01
5.6.130.0130.08021.14
5.6.120.0030.07321.02
5.6.110.0100.04021.20
5.6.100.0130.05020.96
5.6.90.0170.05321.30
5.6.80.0100.07720.57
5.6.70.0100.06720.48
5.6.60.0100.07020.49
5.6.50.0170.06720.57
5.6.40.0030.05020.40
5.6.30.0170.06020.38
5.6.20.0130.07320.57
5.6.10.0170.06720.54
5.6.00.0170.05320.50
5.5.380.0070.07720.59
5.5.370.0070.04020.43
5.5.360.0070.05320.61
5.5.350.0070.08320.58
5.5.340.0100.06720.84
5.5.330.0100.05020.89
5.5.320.0030.04720.91
5.5.310.0100.07721.04
5.5.300.0030.04320.89
5.5.290.0000.07021.00
5.5.280.0170.06720.88
5.5.270.0100.05720.78
5.5.260.0100.06721.05
5.5.250.0070.05720.89
5.5.240.0030.08020.23
5.5.230.0100.07320.41
5.5.220.0100.03720.16
5.5.210.0000.07020.42
5.5.200.0070.04320.37
5.5.190.0100.07720.32
5.5.180.0030.08020.33
5.5.160.0070.04720.20
5.5.150.0030.05720.41
5.5.140.0070.03720.29
5.5.130.0030.04320.34
5.5.120.0130.06720.23
5.5.110.0200.05020.15
5.5.100.0130.06720.32
5.5.90.0070.07720.14
5.5.80.0100.06320.32
5.5.70.0070.07720.14
5.5.60.0070.04720.29
5.5.50.0000.04320.13
5.5.40.0030.05720.16
5.5.30.0030.05720.29
5.5.20.0170.03320.05
5.5.10.0130.05720.19
5.5.00.0030.08020.18
5.4.450.0070.04719.58
5.4.440.0070.07719.50
5.4.430.0070.07719.54
5.4.420.0130.04019.42
5.4.410.0030.07319.14
5.4.400.0070.04019.25
5.4.390.0130.07019.28
5.4.380.0000.04719.02
5.4.370.0030.08319.20
5.4.360.0030.07319.25
5.4.350.0100.06719.12
5.4.340.0130.06719.12
5.4.320.0030.07319.24
5.4.310.0170.06319.25
5.4.300.0130.07319.25
5.4.290.0100.04319.24
5.4.280.0200.06719.27
5.4.270.0070.07319.20
5.4.260.0030.07018.93
5.4.250.0100.08019.11
5.4.240.0030.04019.27
5.4.230.0030.04719.25
5.4.220.0070.06719.19
5.4.210.0070.07019.23
5.4.200.0000.04318.93
5.4.190.0100.03019.23
5.4.180.0000.05019.31
5.4.170.0030.07719.27
5.4.160.0000.08019.21
5.4.150.0100.04318.92
5.4.140.0030.04716.57
5.4.130.0070.03316.56
5.4.120.0100.03716.48
5.4.110.0100.04316.57
5.4.100.0030.04316.48
5.4.90.0070.04016.55
5.4.80.0100.06016.46
5.4.70.0130.03316.50
5.4.60.0030.07716.48
5.4.50.0000.04716.50
5.4.40.0070.04016.50
5.4.30.0130.03316.50
5.4.20.0030.04316.52
5.4.10.0070.05716.48
5.4.00.0100.03015.89
5.3.290.0070.07714.66
5.3.280.0130.06014.55
5.3.270.0000.05014.42
5.3.260.0130.06714.47
5.3.250.0070.07314.58
5.3.240.0130.06714.59
5.3.230.0030.08314.56
5.3.220.0100.05714.55
5.3.210.0100.04014.56
5.3.200.0000.08014.48
5.3.190.0170.06714.48
5.3.180.0070.04314.55
5.3.170.0070.06314.52
5.3.160.0100.06714.55
5.3.150.0030.07714.48
5.3.140.0030.07014.53
5.3.130.0070.07014.39
5.3.120.0070.04714.53
5.3.110.0070.06714.41
5.3.100.0100.06314.03
5.3.90.0100.03713.88
5.3.80.0100.06313.99
5.3.70.0070.07314.00
5.3.60.0070.04014.01
5.3.50.0030.04713.94
5.3.40.0070.04013.80
5.3.30.0030.07313.89
5.3.20.0130.06713.70
5.3.10.0030.04313.61
5.3.00.0130.03013.39
5.2.170.0030.03711.15
5.2.160.0070.03710.98
5.2.150.0100.05311.07
5.2.140.0070.02711.16
5.2.130.0030.03710.92
5.2.120.0070.04711.19
5.2.110.0000.05311.15
5.2.100.0100.05711.09
5.2.90.0030.04011.05
5.2.80.0100.05710.89
5.2.70.0000.04010.89
5.2.60.0100.03310.88
5.2.50.0030.05011.02
5.2.40.0130.02311.00
5.2.30.0070.02310.80
5.2.20.0000.04310.83
5.2.10.0030.05310.76
5.2.00.0070.03010.72
5.1.60.0070.05010.06
5.1.50.0070.05710.03
5.1.40.0030.05010.01
5.1.30.0030.03310.27
5.1.20.0100.04010.35
5.1.10.0030.0239.95
5.1.00.0030.02310.10
5.0.50.0000.0278.60
5.0.40.0030.0208.24
5.0.30.0000.0338.27
5.0.20.0030.0178.30
5.0.10.0000.0208.02
5.0.00.0000.0308.22
4.4.90.0030.0177.47
4.4.80.0030.0307.47
4.4.70.0000.0207.47
4.4.60.0000.0237.47
4.4.50.0000.0207.47
4.4.40.0070.0507.47
4.4.30.0030.0307.47
4.4.20.0070.0137.47
4.4.10.0070.0137.47
4.4.00.0000.0377.47
4.3.110.0000.0177.47
4.3.100.0030.0137.47
4.3.90.0000.0177.47
4.3.80.0000.0277.47
4.3.70.0000.0177.47
4.3.60.0000.0177.47
4.3.50.0000.0207.47
4.3.40.0000.0307.47
4.3.30.0030.0137.47
4.3.20.0000.0177.47
4.3.10.0000.0177.47
4.3.00.0030.0107.47

preferences:
67.53 ms | 401 KiB | 5 Q