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->a2x(current($this->context), $this->res)->asXML(); } 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 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.0110.00719.06
8.3.50.0120.00822.03
8.3.40.0040.01219.09
8.3.30.0090.00619.13
8.3.20.0060.00319.27
8.3.10.0080.00021.30
8.3.00.0040.00422.10
8.2.180.0150.00417.13
8.2.170.0210.00022.96
8.2.160.0030.01220.53
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00021.23
8.2.110.0090.00020.77
8.2.100.0040.00817.97
8.2.90.0030.00519.32
8.2.80.0080.00018.29
8.2.70.0040.00417.88
8.2.60.0080.00018.02
8.2.50.0000.00818.07
8.2.40.0040.00418.30
8.2.30.0000.00721.31
8.2.20.0030.00617.95
8.2.10.0050.00318.15
8.2.00.0070.00017.94
8.1.280.0130.00625.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0050.00522.71
8.1.230.0110.00021.03
8.1.220.0030.00618.77
8.1.210.0030.00519.02
8.1.200.0000.01017.60
8.1.190.0000.00917.78
8.1.180.0040.00418.10
8.1.170.0000.00818.84
8.1.160.0030.00619.04
8.1.150.0090.00018.91
8.1.140.0050.00217.58
8.1.130.0000.00718.10
8.1.120.0080.00017.72
8.1.110.0000.00717.52
8.1.100.0000.00717.51
8.1.90.0070.00017.69
8.1.80.0030.00517.76
8.1.70.0080.00017.56
8.1.60.0030.00617.82
8.1.50.0000.00817.53
8.1.40.0000.00817.76
8.1.30.0060.00317.89
8.1.20.0000.00917.91
8.1.10.0050.00317.81
8.1.00.0050.00317.69
8.0.300.0000.00720.23
8.0.290.0060.00317.30
8.0.280.0000.00718.61
8.0.270.0050.00317.40
8.0.260.0000.00717.22
8.0.250.0030.00717.24
8.0.240.0040.00717.06
8.0.230.0000.00717.29
8.0.220.0040.00417.18
8.0.210.0040.00317.18
8.0.200.0000.00617.25
8.0.190.0040.00417.19
8.0.180.0000.00717.21
8.0.170.0070.00017.21
8.0.160.0000.00817.02
8.0.150.0070.00017.19
8.0.140.0040.00417.09
8.0.130.0060.00013.64
8.0.120.0040.00417.05
8.0.110.0040.00417.09
8.0.100.0000.00717.20
8.0.90.0040.00417.13
8.0.80.0060.01517.26
8.0.70.0030.00517.26
8.0.60.0030.00517.14
8.0.50.0000.00817.17
8.0.30.0110.00917.30
8.0.20.0060.01217.52
8.0.10.0040.00417.19
8.0.00.0080.01117.09
7.4.330.0000.00517.03
7.4.320.0000.00716.86
7.4.300.0040.00416.69
7.4.290.0000.00716.60
7.4.280.0060.00316.77
7.4.270.0000.00716.89
7.4.260.0050.00013.59
7.4.250.0040.00416.77
7.4.240.0000.00816.79
7.4.230.0000.00716.79
7.4.220.0130.01016.83
7.4.210.0090.01016.80
7.4.200.0000.00716.84
7.4.190.0050.00216.65
7.4.160.0060.00916.59
7.4.150.0100.00917.40
7.4.140.0110.00917.86
7.4.130.0080.00916.69
7.4.120.0080.00916.82
7.4.110.0120.00416.63
7.4.100.0120.01216.68
7.4.90.0100.00716.55
7.4.80.0140.00319.39
7.4.70.0060.01016.71
7.4.60.0070.01016.77
7.4.50.0040.00416.66
7.4.40.0060.00922.77
7.4.30.0140.00416.95
7.4.00.0040.01415.24
7.3.330.0060.00013.70
7.3.320.0110.00413.59
7.3.310.0030.00316.71
7.3.300.0040.00316.61
7.3.290.0000.01816.65
7.3.280.0090.00716.64
7.3.270.0130.00617.40
7.3.260.0120.00818.24
7.3.250.0110.00816.74
7.3.240.0100.00716.65
7.3.230.0000.01816.59
7.3.210.0140.00716.72
7.3.200.0150.00419.39
7.3.190.0090.01316.61
7.3.180.0120.00816.73
7.3.170.0120.00416.61
7.3.160.0130.00316.75
7.3.120.0000.01415.09
7.2.330.0100.00717.09
7.2.320.0160.00717.03
7.2.310.0090.00917.04
7.2.300.0080.00817.14
7.2.290.0170.00016.72
7.2.60.0070.01017.35
7.1.200.0090.00316.04
7.1.70.0030.00717.27
7.1.60.0060.01919.40
7.1.50.0130.01017.06
7.1.00.0030.06322.46
7.0.200.0130.00916.43
7.0.140.0000.07022.20
7.0.90.0670.07020.06
7.0.80.0630.08320.00
7.0.70.0600.07320.23
7.0.60.0470.07720.24
7.0.50.0300.07720.49
7.0.40.0270.05320.25
7.0.30.0030.05720.14
7.0.20.0100.07720.12
7.0.10.0130.06720.08
7.0.00.0130.06320.07
5.6.280.0030.07321.19
5.6.240.0070.07320.80
5.6.230.0100.08320.84
5.6.220.0100.05020.84
5.6.210.0030.08720.85
5.6.200.0130.08021.27
5.6.190.0000.08321.37
5.6.180.0070.08321.18
5.6.170.0200.07021.32
5.6.160.0030.04721.21
5.6.150.0070.08321.18
5.6.140.0030.05721.07
5.6.130.0130.04721.18
5.6.120.0200.06021.21
5.6.110.0070.07021.06
5.6.100.0030.08321.21
5.6.90.0130.05721.18
5.6.80.0070.07720.48
5.6.70.0070.07020.52
5.6.60.0100.07720.55
5.6.50.0070.08020.53
5.6.40.0130.07320.45
5.6.30.0070.04320.43
5.6.20.0000.08720.58
5.6.10.0030.07720.54
5.6.00.0170.06020.57
5.5.380.0170.06320.61
5.5.370.0100.07020.56
5.5.360.0030.07020.55
5.5.350.0170.08020.55
5.5.340.0000.09020.93
5.5.330.0070.08020.93
5.5.320.0100.06720.82
5.5.310.0130.07721.03
5.5.300.0030.07721.13
5.5.290.0070.05721.04
5.5.280.0030.06721.08
5.5.270.0130.08021.08
5.5.260.0130.08021.11
5.5.250.0070.07020.87
5.5.240.0030.08020.50
5.5.230.0100.04720.48
5.5.220.0000.05320.46
5.5.210.0070.08020.39
5.5.200.0200.07020.43
5.5.190.0030.08320.41
5.5.180.0100.08320.43
5.5.160.0100.07020.22
5.5.150.0130.08020.43
5.5.140.0070.07320.19
5.5.130.0100.08020.19
5.5.120.0130.07320.43
5.5.110.0070.05720.45
5.5.100.0200.06320.36
5.5.90.0200.06720.22
5.5.80.0070.07020.33
5.5.70.0070.07320.16
5.5.60.0030.06020.31
5.5.50.0070.07720.22
5.5.40.0000.07020.30
5.5.30.0030.04720.17
5.5.20.0070.03720.25
5.5.10.0070.07320.27
5.5.00.0100.05020.26
5.4.450.0070.07319.55
5.4.440.0030.04319.60
5.4.430.0070.08319.43
5.4.420.0100.07019.59
5.4.410.0100.08019.43
5.4.400.0100.06719.28
5.4.390.0070.07319.02
5.4.380.0070.07319.10
5.4.370.0170.06719.05
5.4.360.0170.07319.24
5.4.350.0200.04719.25
5.4.340.0070.07719.23
5.4.320.0030.05719.11
5.4.310.0030.04319.28
5.4.300.0030.08019.25
5.4.290.0030.07319.22
5.4.280.0100.07719.22
5.4.270.0000.04719.28
5.4.260.0170.07019.26
5.4.250.0000.08318.97
5.4.240.0130.05719.24
5.4.230.0130.06719.05
5.4.220.0100.06319.03
5.4.210.0030.07719.25
5.4.200.0070.05319.36
5.4.190.0030.05319.30
5.4.180.0170.05019.17
5.4.170.0170.05718.93
5.4.160.0130.07019.09
5.4.150.0100.06719.26
5.4.140.0100.07016.48
5.4.130.0070.07016.31
5.4.120.0000.08316.53
5.4.110.0000.06016.46
5.4.100.0070.07716.57
5.4.90.0100.06716.48
5.4.80.0030.03716.56
5.4.70.0070.06316.44
5.4.60.0130.02716.51
5.4.50.0030.05716.45
5.4.40.0030.03716.44
5.4.30.0070.03316.53
5.4.20.0070.03316.55
5.4.10.0030.03716.49
5.4.00.0070.05715.93
5.3.290.0070.06714.66
5.3.280.0100.07714.50
5.3.270.0070.07314.43
5.3.260.0030.08014.47
5.3.250.0070.07714.60
5.3.240.0030.05714.60
5.3.230.0100.07014.46
5.3.220.0070.07314.43
5.3.210.0030.06714.43
5.3.200.0030.07314.57
5.3.190.0100.07714.39
5.3.180.0070.04014.42
5.3.170.0000.05014.50
5.3.160.0070.04714.55
5.3.150.0000.04314.52
5.3.140.0030.03714.56
5.3.130.0030.04014.51
5.3.120.0030.03714.41
5.3.110.0000.04014.50
5.3.100.0130.05313.91
5.3.90.0000.05314.01
5.3.80.0030.03714.00
5.3.70.0170.06714.02
5.3.60.0000.04013.98
5.3.50.0070.03313.95
5.3.40.0070.03313.80
5.3.30.0130.06313.77
5.3.20.0030.03013.55
5.3.10.0070.02713.42
5.3.00.0030.07713.61
5.2.170.0070.06311.19
5.2.160.0000.03311.14
5.2.150.0000.02711.00
5.2.140.0000.03011.21
5.2.130.0000.02711.06
5.2.120.0030.02710.89
5.2.110.0000.03311.06
5.2.100.0030.03011.11
5.2.90.0100.04311.10
5.2.80.0000.05011.11
5.2.70.0000.03011.09
5.2.60.0000.02711.01
5.2.50.0000.04710.87
5.2.40.0030.02710.98
5.2.30.0000.03011.03
5.2.20.0070.03310.98
5.2.10.0030.04710.91
5.2.00.0070.02710.77
5.1.60.0070.0209.98
5.1.50.0000.02710.01
5.1.40.0030.05310.03
5.1.30.0000.03010.39
5.1.20.0070.02010.26
5.1.10.0000.03010.11
5.1.00.0030.0279.95
5.0.50.0000.0208.58
5.0.40.0030.0208.50
5.0.30.0000.0338.07
5.0.20.0030.0278.20
5.0.10.0070.0408.00
5.0.00.0070.0608.25
4.4.90.0030.0237.21
4.4.80.0000.0307.21
4.4.70.0030.0137.21
4.4.60.0000.0177.21
4.4.50.0000.0237.21
4.4.40.0030.0177.21
4.4.30.0000.0207.21
4.4.20.0030.0137.21
4.4.10.0000.0207.21
4.4.00.0030.0577.21
4.3.110.0030.0177.21
4.3.100.0030.0237.21
4.3.90.0000.0137.21
4.3.80.0030.0577.21
4.3.70.0030.0337.21
4.3.60.0000.0337.21
4.3.50.0030.0337.21
4.3.40.0000.0437.21
4.3.30.0030.0337.21
4.3.20.0030.0277.21
4.3.10.0000.0407.21
4.3.00.0000.0337.21

preferences:
50.85 ms | 401 KiB | 5 Q