3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { const ATTRIBUTE_PREFIX = '@'; private $xml; public function __construct(SimpleXmlIterator $xml) { $this->xml = $xml; } private function getElement($offset) { $isAttribute = false; if (substr($offset, 0, 1) == self::ATTRIBUTE_PREFIX) { $offset = substr($offset, 1); $isAttribute = false; } if (false !== $this->xml->$offset->asXML() && !$isAttribute) { $xml = $this->xml->$offset; } else { $xml = $this->xml[$offset]; } } public function offsetExists($offset) { return !is_null($this->getElement($offset)); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } $xml = $this->getElement($offset); if (is_null($xml)) { throw new RuntimeException('unknown node or attribute "' . $offset . '"'); } return new self($xml); } public function offsetSet($offset, $value) { throw new RuntimeException('This is readonly. writing to "' . (string) $offset . '" with value "' . (string) $value . '" not possible'); } public function offsetUnset($offset) { throw new RuntimeException('This is readonly. Unsetting "' . (string) $offset . '" not possible'); } public function getIterator() { return $this->xml; } public function __toString() { return (string) $this->xml; } } $xml = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading foo="bar">Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $simple = new SimpleXmlIterator($xml); $xml = new XmlArrayAccessIterator($simple); echo $xml['note']['to']; echo $xml['note']['recursive']['val'][1]; echo $xml['note']['heading']['@foo'];

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.0170.00318.93
8.3.50.0070.01322.08
8.3.40.0090.00619.01
8.3.30.0110.00419.42
8.3.20.0110.00820.48
8.3.10.0050.00323.91
8.3.00.0070.00422.70
8.2.180.0120.00817.13
8.2.170.0090.00622.96
8.2.160.0070.00722.38
8.2.150.0120.00324.18
8.2.140.0120.00324.66
8.2.130.0070.00026.16
8.2.120.0140.00719.73
8.2.110.0060.00321.36
8.2.100.0040.00818.09
8.2.90.0030.00619.60
8.2.80.0080.00018.03
8.2.70.0000.00818.00
8.2.60.0040.00418.28
8.2.50.0030.00518.07
8.2.40.0040.00718.53
8.2.30.0070.00318.46
8.2.20.0000.00918.12
8.2.10.0050.00319.84
8.2.00.0050.00318.02
8.1.280.0090.00925.92
8.1.270.0030.01224.11
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0120.00923.98
8.1.230.0120.00021.10
8.1.220.0080.00018.01
8.1.210.0080.00018.77
8.1.200.0030.00617.38
8.1.190.0040.00417.89
8.1.180.0000.00918.10
8.1.170.0030.00518.88
8.1.160.0030.00522.31
8.1.150.0080.00018.88
8.1.140.0090.00017.68
8.1.130.0040.00418.10
8.1.120.0000.00817.80
8.1.110.0040.00417.67
8.1.100.0050.00217.74
8.1.90.0000.00717.76
8.1.80.0040.00417.78
8.1.70.0000.00717.73
8.1.60.0030.00617.91
8.1.50.0000.00817.73
8.1.40.0050.00317.90
8.1.30.0000.00917.80
8.1.20.0030.00517.91
8.1.10.0050.00317.75
8.1.00.0060.00317.64
8.0.300.0030.00518.77
8.0.290.0070.00017.30
8.0.280.0030.00318.76
8.0.270.0000.00717.54
8.0.260.0030.00317.16
8.0.250.0000.00717.25
8.0.240.0000.00717.30
8.0.230.0000.00817.17
8.0.220.0040.00417.13
8.0.210.0050.00217.13
8.0.200.0050.00217.16
8.0.190.0000.00717.16
8.0.180.0040.00417.21
8.0.170.0050.00317.14
8.0.160.0000.00717.22
8.0.150.0030.00517.25
8.0.140.0000.00717.07
8.0.130.0000.00613.54
8.0.120.0040.00417.13
8.0.110.0000.00817.20
8.0.100.0080.00017.20
8.0.90.0030.00517.03
8.0.80.0040.01517.15
8.0.70.0050.00217.27
8.0.60.0040.00417.34
8.0.50.0000.00717.25
8.0.30.0150.00517.52
8.0.20.0150.00517.62
8.0.10.0000.00817.20
8.0.00.0090.00917.06
7.4.330.0000.00515.39
7.4.320.0030.00316.76
7.4.300.0000.00616.69
7.4.290.0000.00716.79
7.4.280.0030.00316.68
7.4.270.0080.00416.84
7.4.260.0000.00716.98
7.4.250.0000.00716.79
7.4.240.0020.00516.79
7.4.230.0050.00216.89
7.4.220.0120.00916.90
7.4.210.0110.00516.89
7.4.200.0050.00216.77
7.4.190.0050.00316.94
7.4.160.0130.01016.86
7.4.150.0160.01017.40
7.4.140.0100.01017.86
7.4.130.0120.00716.83
7.4.120.0100.00716.82
7.4.110.0100.00717.00
7.4.100.0180.00316.82
7.4.90.0090.00916.74
7.4.80.0080.01516.85
7.4.70.0030.01316.64
7.4.60.0090.01216.65
7.4.50.0000.00516.37
7.4.40.0030.01022.77
7.4.30.0090.00916.91
7.4.10.0030.01614.94
7.4.00.0080.00814.85
7.3.330.0030.00313.69
7.3.320.0000.00513.78
7.3.310.0080.00016.79
7.3.300.0000.00716.66
7.3.290.0060.00916.69
7.3.280.0090.00916.71
7.3.270.0100.00617.40
7.3.260.0100.01416.77
7.3.250.0080.01016.74
7.3.240.0100.01016.76
7.3.230.0110.00716.83
7.3.210.0030.01316.77
7.3.200.0140.00319.39
7.3.190.0110.01016.75
7.3.180.0120.00916.77
7.3.170.0100.01316.78
7.3.160.0130.00716.73
7.3.130.0120.00615.00
7.3.120.0100.00814.96
7.3.110.0060.01314.86
7.3.100.0030.01614.91
7.3.90.0070.00714.95
7.3.80.0080.00414.87
7.3.70.0000.01714.92
7.3.60.0030.00614.73
7.3.50.0100.00714.85
7.3.40.0080.00314.57
7.3.30.0030.01014.75
7.3.20.0100.00716.84
7.3.10.0060.00316.48
7.3.00.0000.00816.69
7.2.330.0090.00917.03
7.2.320.0040.01316.81
7.2.310.0070.01616.73
7.2.300.0070.01017.14
7.2.290.0070.01016.93
7.2.260.0130.00314.93
7.2.250.0070.01415.14
7.2.240.0100.00715.16
7.2.230.0040.00715.37
7.2.220.0070.01415.14
7.2.210.0090.00315.21
7.2.200.0070.00314.91
7.2.190.0110.01115.06
7.2.180.0030.01214.84
7.2.170.0040.01515.12
7.2.160.0120.00315.19
7.2.150.0040.00716.81
7.2.140.0090.00316.61
7.2.130.0070.00716.95
7.2.120.0070.00716.93
7.2.110.0030.01216.66
7.2.100.0050.00816.93
7.2.90.0100.00716.98
7.2.80.0070.00717.12
7.2.70.0050.01016.95
7.2.60.0050.00916.97
7.2.50.0060.00617.08
7.2.40.0030.01016.83
7.2.30.0040.01116.85
7.2.20.0060.00917.03
7.2.10.0000.01417.00
7.2.00.0050.00618.04
7.1.330.0060.00915.70
7.1.320.0100.01015.92
7.1.310.0070.00715.71
7.1.300.0030.01715.71
7.1.290.0140.00015.87
7.1.280.0070.00315.79
7.1.270.0050.00516.04
7.1.260.0030.01015.90
7.1.250.0070.00315.59
7.1.240.0080.00416.09
7.1.230.0070.00715.63
7.1.220.0110.00415.67
7.1.210.0060.00615.45
7.1.200.0050.00715.70
7.1.190.0040.00815.57
7.1.180.0110.00415.58
7.1.170.0000.00915.62
7.1.160.0100.00315.78
7.1.150.0060.00615.88
7.1.140.0060.00315.64
7.1.130.0040.00815.71
7.1.120.0000.01115.97
7.1.110.0080.00315.75
7.1.100.0040.00717.10
7.1.90.0070.00415.90
7.1.80.0000.01115.87
7.1.70.0030.00816.29
7.1.60.0050.01317.60
7.1.50.0020.00916.51
7.1.40.0070.00715.89
7.1.30.0070.00715.90
7.1.20.0090.00615.67
7.1.10.0030.00615.94
7.1.00.0020.04519.21
7.0.330.0000.01015.05
7.0.320.0060.00915.13
7.0.310.0060.00315.06
7.0.300.0080.00015.23
7.0.290.0050.00515.07
7.0.280.0040.00815.38
7.0.270.0040.00415.40
7.0.260.0000.00815.45
7.0.250.0110.00415.56
7.0.240.0060.00615.51
7.0.230.0080.00415.49
7.0.220.0030.01015.20
7.0.210.0110.00415.39
7.0.200.0030.00816.12
7.0.190.0070.00715.23
7.0.180.0030.01015.61
7.0.170.0080.00415.42
7.0.160.0080.00415.37
7.0.150.0060.00915.23
7.0.140.0030.04018.73
7.0.130.0100.00315.78
7.0.120.0060.00315.53
7.0.110.0040.00415.34
7.0.100.0030.00915.27
7.0.90.0030.01015.23
7.0.80.0080.00815.24
7.0.70.0000.00815.63
7.0.60.0130.03017.84
7.0.50.0010.02716.93
7.0.40.0080.03817.03
7.0.30.0170.02216.98
7.0.20.0130.03416.79
7.0.10.0120.04216.79
7.0.00.0020.05016.75
5.6.400.0030.00514.66
5.6.390.0070.00714.51
5.6.380.0000.01414.41
5.6.370.0070.00714.16
5.6.360.0000.01214.13
5.6.350.0000.00814.71
5.6.340.0090.00014.28
5.6.330.0110.00314.48
5.6.320.0070.00314.56
5.6.310.0000.00914.70
5.6.300.0000.00914.33
5.6.290.0030.01014.52
5.6.280.0050.03917.81
5.6.270.0040.00714.30
5.6.260.0030.00714.58
5.6.250.0080.00014.59
5.6.240.0000.01214.31
5.6.230.0030.00914.38
5.6.220.0050.00314.32
5.6.210.0070.03017.61
5.6.200.0040.02416.31
5.6.190.0060.04617.50
5.6.180.0180.03717.55
5.6.170.0170.04217.44
5.6.160.0120.02817.54
5.6.150.0060.02416.32
5.6.140.0070.04416.45
5.6.130.0050.05016.46
5.6.120.0050.05017.78
5.6.110.0080.03318.02
5.6.100.0060.04117.84
5.6.90.0120.04417.66
5.6.80.0090.03717.36
5.6.70.0070.00714.28
5.6.60.0060.00914.22
5.6.50.0070.00714.63
5.6.40.0030.01014.07
5.6.30.0090.00014.25
5.6.20.0000.01114.27
5.6.10.0000.01414.18
5.6.00.0000.01514.37
5.5.380.0000.01214.69
5.5.370.0030.00814.55
5.5.360.0110.00414.27
5.5.350.0050.04017.52
5.5.340.0030.04216.35
5.5.330.0070.03717.58
5.5.320.0170.04517.50
5.5.310.0120.04817.44
5.5.300.0070.02816.27
5.5.290.0120.03916.24
5.5.280.0070.02917.64
5.5.270.0110.04117.69
5.5.260.0070.03917.64
5.5.250.0030.04117.57
5.5.240.1710.02017.24
5.5.230.0040.00414.51
5.5.220.0000.01114.37
5.5.210.0040.01114.32
5.5.200.0160.00014.17
5.5.190.0070.00714.50
5.5.180.0030.01014.51
5.5.170.0070.00714.59
5.5.160.0110.00414.48
5.5.150.0030.00913.93
5.5.140.0110.00414.58
5.5.130.0160.00014.39
5.5.120.0030.00614.38
5.5.110.0030.01014.17
5.5.100.0100.00614.31
5.5.90.0090.00014.28
5.5.80.0060.00914.10
5.5.70.0030.01114.31
5.5.60.0000.00814.23
5.5.50.0150.00014.20
5.5.40.0040.01114.21
5.5.30.0030.01414.27
5.5.20.0070.00314.34
5.5.10.0040.01214.23
5.5.00.0120.00314.51
5.4.450.0130.02815.42
5.4.440.0080.02715.41
5.4.430.0430.02315.24
5.4.420.0180.03015.43
5.4.410.0080.02615.23
5.4.400.0080.03014.96
5.4.390.0070.03315.17
5.4.380.0050.03514.82
5.4.370.0180.02615.06
5.4.360.0110.03114.99
5.4.350.0110.03314.97
5.4.340.0160.02615.05
5.4.330.0070.00711.32
5.4.320.0040.02411.99
5.4.310.0060.02312.06
5.4.300.0070.01912.03
5.4.290.0040.02411.95
5.4.280.0050.02211.87
5.4.270.0030.02311.83
5.4.260.0050.02111.92
5.4.250.0010.02312.00
5.4.240.0040.02711.78
5.4.230.0090.02211.92
5.4.220.0080.02311.78
5.4.210.0040.02311.82
5.4.200.0060.02411.82
5.4.190.0090.02511.86
5.4.180.0130.02211.91
5.4.170.0140.02211.88
5.4.160.0090.02911.81
5.4.150.0120.02511.92
5.4.140.0170.03511.76
5.4.130.0100.02611.79
5.4.120.0140.02211.59
5.4.110.0090.03211.53
5.4.100.0110.02411.63
5.4.90.0120.02311.53
5.4.80.0130.02111.78
5.4.70.0120.03811.70
5.4.60.0080.02511.59
5.4.50.0090.02311.49
5.4.40.0120.02311.72
5.4.30.0100.02611.67
5.4.20.0100.02611.65
5.4.10.0120.03811.63
5.4.00.0080.02711.25
5.3.290.0040.02311.92
5.3.280.0060.02311.71
5.3.270.0070.03111.75
5.3.260.0220.04911.83
5.3.250.0080.02911.75
5.3.240.0120.02511.78
5.3.230.0150.02411.78
5.3.220.0110.02611.75
5.3.210.0110.02711.78
5.3.200.0080.03311.66
5.3.190.0100.02811.71
5.3.180.0110.02811.88
5.3.170.0190.04711.91
5.3.160.0070.02811.84
5.3.150.0090.02511.81
5.3.140.0140.02211.88
5.3.130.0130.02211.80
5.3.120.0100.02411.79
5.3.110.0130.05311.77
5.3.100.0090.02911.58
5.3.90.0100.02511.54
5.3.80.0110.02711.38
5.3.70.0230.06011.39
5.3.60.0120.02711.43
5.3.50.0080.02611.48
5.3.40.0110.02711.47
5.3.30.0100.02511.50
5.3.20.0090.02511.38
5.3.10.0160.01911.16
5.3.00.0210.06011.24
5.2.170.0140.0349.41
5.2.160.0140.0349.41
5.2.150.0120.0389.42
5.2.140.0120.0369.41
5.2.130.0160.0329.37
5.2.120.0150.0349.37
5.2.110.0130.0349.38
5.2.100.0140.0329.37
5.2.90.0130.0369.38
5.2.80.0130.0639.37
5.2.70.0120.0369.37
5.2.60.0140.0329.32
5.2.50.0200.0289.29
5.2.40.0130.0369.27
5.2.30.0100.0379.23
5.2.20.0140.0359.23
5.2.10.0140.0339.13
5.2.00.0120.0359.00
5.1.60.0130.0278.30
5.1.50.0070.0378.29
5.1.40.0070.0348.28
5.1.30.0100.0368.63
5.1.20.0120.0358.61
5.1.10.0130.0348.32
5.1.00.0130.0328.32
5.0.50.0090.0256.81
5.0.40.0090.0246.66
5.0.30.0090.0396.48
5.0.20.0110.0206.46
5.0.10.0080.0246.43
5.0.00.0060.0396.43
4.4.90.0090.0164.78
4.4.80.0080.0194.76
4.4.70.0080.0184.75
4.4.60.0040.0234.76
4.4.50.0050.0204.77
4.4.40.0090.0274.71
4.4.30.0050.0204.76
4.4.20.0040.0204.84
4.4.10.0080.0174.85
4.4.00.0040.0324.76
4.3.110.0070.0194.67
4.3.100.0070.0174.67
4.3.90.0060.0184.63
4.3.80.0100.0254.58
4.3.70.0080.0174.63
4.3.60.0040.0204.63
4.3.50.0080.0174.63
4.3.40.0070.0284.54
4.3.30.0050.0183.30
4.3.20.0070.0193.28
4.3.10.0060.0163.24
4.3.00.0030.01313.31

preferences:
114.27 ms | 401 KiB | 5 Q