3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xpath = "/bids_offers/market_submit/sem_gen_technical_offer/block_deloading/point"; $xml = new EformDOMDocument(); //$root = $xml->createElement("bids_offers"); //$xml->appendChild($root); $str = <<<XML <?xml version="1.0" encoding="UTF-8" standalone="no"?> <bids_offers> </bids_offers> XML; $xml->loadXML($str); $xml->buildMissingTree($xpath); $xml->formatOutput = true; echo $xml->saveXML(); class EformDOMDocument extends DOMDocument { public $xpath; public function __construct($version = null, $encoding = null) { parent::__construct($version, $encoding); $this->xpath = new DOMXPath($this); } public function setAttributeX($path, $attributeName, $attributeValue) { // check if path returns anything valid if ($this->xpath->query($path)->length == 0) { $this->buildMissingTree($path); } $this->xpath->query($path)->item(0)->setAttribute($attributeName, $attributeValue); } public function buildMissingTree($path) { $missingNodes = array(); $tempPath = $path; // build an array of missing elements in the path while ($this->xpath->query($tempPath)->length == 0) { $tempName = basename($tempPath); $tempPath = dirname($tempPath); // deal with such: testnode[@type='HOT'] or [#] if (strpos($tempName, '[') === FALSE) { // no attributes use $tempName $missingNodes[] = $this->createElement($tempName); } else { // split element name and attribute, create both separate, append attribute to element, push into the aray $tempHolder = explode('[', $tempName); $tempElement = $this->createElement($tempHolder[0]); // [1] is attribute, clean it up, split name and value if (strpos($tempHolder[1], '@') !== FALSE) { // element has attiribute if it has @ in the path piece $attParam = str_replace(array('@', '\'', ']'), '', $tempHolder[1]); $attribute = explode('=', $attParam); $tempElement->setAttribute($attribute[0], $attribute[1]); } // otherwise its a number of the node in the sequence, skip it, as if xml is generated is in order, //previous nodes should exist already $missingNodes[] = $tempElement; $tempElement = null; } } // build the structure with missing elements (use $missingNodes array) // get existing end //echo $tempPath; //var_dump($missingNodes[0]); $currentElement = $this->xpath->query($tempPath)->item(0); while (($newElement = array_pop($missingNodes)) !== NULL) { $currentElement->appendChild($newElement); $currentElement = $newElement; } } /** * Checks if document has at least one element with a name (and optional attribute) provided * * @param string $name * @return mixed */ public function hasElement($name, $attribute = '') { $elements = $this->getElementsByTagName($name); if ($elements->length > 0) { if ($attribute == '') { return true; } // if attribute provided, check through the list for the element with provided attribute for ($i = 0; $i < $elements->length; $i++) { // TODO fix that checks on attibute value too, not just name if ($elements->item($i)->hasAttribute($attribute)) { return $elements->item($i); //return true; } } } return false; } /** * * @param string $name * @param string $attributeParameters provided as "attr1name=value1;attr2name=value2...etc." * @return DOMElement */ public function createElementWithAttributes($name, $attributeParameters = '') { $element = $this->createElement($name); // atributes provided as "attr1name=value1;attr2name=value2...etc." if ($attributeParameters != '') { // separate multiple parameters $attributes = explode(';', $attributeParameters); // add parameters to the element foreach ($attributes as $attribute) { $keyvalue = explode('=', $attribute); $element->setAttribute($keyvalue[0], $keyvalue[1]); } } return $element; } }

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.40.0150.00419.12
8.3.30.0080.00819.46
8.3.20.0030.00520.76
8.3.10.0040.00423.98
8.3.00.0030.00619.76
8.2.170.0000.01522.96
8.2.160.0090.00620.76
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00022.76
8.2.110.0060.00322.58
8.2.100.0090.00318.28
8.2.90.0030.00619.67
8.2.80.0060.00318.13
8.2.70.0040.00717.99
8.2.60.0030.00518.41
8.2.50.0080.00018.13
8.2.40.0080.00020.26
8.2.30.0040.00418.55
8.2.20.0000.00818.16
8.2.10.0000.00818.65
8.2.00.0070.00418.31
8.1.270.0060.00324.22
8.1.260.0060.00326.35
8.1.250.0000.00828.09
8.1.240.0100.00024.29
8.1.230.0040.00819.39
8.1.220.0000.00817.90
8.1.210.0040.00418.77
8.1.200.0060.00317.85
8.1.190.0000.00817.73
8.1.180.0040.00718.10
8.1.170.0090.00018.96
8.1.160.0040.00422.36
8.1.150.0040.00719.00
8.1.140.0040.00417.81
8.1.130.0040.00418.17
8.1.120.0070.00017.98
8.1.110.0030.00717.79
8.1.100.0040.00417.72
8.1.90.0000.00817.97
8.1.80.0030.00617.91
8.1.70.0000.00717.83
8.1.60.0030.00718.05
8.1.50.0000.00917.88
8.1.40.0030.00517.90
8.1.30.0040.00418.09
8.1.20.0000.00917.98
8.1.10.0000.00917.88
8.1.00.0000.00818.01
8.0.300.0040.00419.43
8.0.290.0000.00817.55
8.0.280.0070.00018.87
8.0.270.0000.00717.52
8.0.260.0070.00017.61
8.0.250.0030.00317.27
8.0.240.0000.00717.48
8.0.230.0070.00017.46
8.0.220.0000.00717.23
8.0.210.0000.00717.37
8.0.200.0030.00317.42
8.0.190.0040.00417.42
8.0.180.0050.00217.44
8.0.170.0000.00817.20
8.0.160.0040.00417.27
8.0.150.0000.00717.21
8.0.140.0000.00717.23
8.0.130.0060.00313.83
8.0.120.0040.00415.41
8.0.110.0040.00515.46
8.0.100.0040.00615.47
8.0.90.0040.00515.51
8.0.80.0090.00715.63
8.0.70.0080.00215.57
8.0.60.0040.00415.55
8.0.50.0050.00315.61
8.0.30.0070.00916.29
8.0.20.0110.00516.24
8.0.10.0080.00115.56
8.0.00.0080.00716.09
7.4.330.0060.00015.00
7.4.320.0000.00616.97
7.4.300.0000.00617.01
7.4.290.0050.00216.96
7.4.280.0040.00417.03
7.4.270.0000.00717.01
7.4.260.0000.00717.03
7.4.250.0020.00615.31
7.4.240.0040.00415.91
7.4.230.0060.00415.30
7.4.220.0090.00715.31
7.4.210.0060.00916.20
7.4.200.0070.00215.38
7.4.190.0020.00615.48
7.4.180.0000.00713.87
7.4.160.0080.00315.28
7.4.150.0080.00615.60
7.4.140.0060.00816.45
7.4.130.0080.00715.87
7.4.120.0040.01115.89
7.4.110.0130.00215.18
7.4.100.0110.00415.30
7.4.90.0090.00615.20
7.4.80.0080.00916.49
7.4.70.0090.00415.37
7.4.60.0070.00815.24
7.4.50.0080.00115.24
7.4.40.0080.00515.16
7.4.30.0060.00715.34
7.4.20.0060.00313.71
7.4.10.0090.00714.59
7.4.00.0070.00814.80
7.3.330.0000.00613.88
7.3.320.0030.00313.79
7.3.310.0020.00715.38
7.3.300.0060.00315.29
7.3.290.0050.00815.21
7.3.280.0130.00516.12
7.3.270.0070.00615.62
7.3.260.0080.00615.27
7.3.250.0070.00815.81
7.3.240.0080.00615.42
7.3.230.0070.00615.38
7.3.220.0090.00013.53
7.3.210.0080.00715.23
7.3.200.0070.00716.58
7.3.190.0100.00615.25
7.3.180.0110.00515.16
7.3.170.0090.00415.34
7.3.160.0090.00415.19
7.3.150.0000.00813.58
7.3.140.0020.00413.63
7.3.130.0050.01014.64
7.3.120.0030.01014.78
7.3.110.0080.00614.47
7.3.100.0060.00614.64
7.3.90.0040.00614.77
7.3.80.0070.00314.52
7.3.70.0030.00714.63
7.3.60.0030.00714.60
7.3.50.0070.00314.67
7.3.40.0070.00414.51
7.3.30.0060.00514.63
7.3.20.0080.00516.31
7.3.10.0060.00616.57
7.3.00.0060.00616.54
7.2.340.0060.00613.53
7.2.330.0120.00415.51
7.2.320.0120.00615.32
7.2.310.0070.00715.54
7.2.300.0130.00215.32
7.2.290.0070.00815.57
7.2.280.0090.00413.90
7.2.270.0080.00513.86
7.2.260.0070.01014.77
7.2.250.0070.01014.75
7.2.240.0090.00514.87
7.2.230.0050.01014.76
7.2.220.0070.00714.75
7.2.210.0070.00514.72
7.2.200.0060.00714.89
7.2.190.0090.00314.87
7.2.180.0070.00614.66
7.2.170.0050.01014.85
7.2.160.0110.00314.93
7.2.150.0050.01016.56
7.2.140.0050.00916.56
7.2.130.0060.00816.80
7.2.120.0050.00816.68
7.2.110.0050.00816.76
7.2.100.0060.00716.82
7.2.90.0040.00916.71
7.2.80.0080.00616.89
7.2.70.0070.00716.70
7.2.60.0080.00616.78
7.2.50.0060.00516.65
7.2.40.0060.00616.71
7.2.30.0070.00716.80
7.2.20.0090.00516.78
7.2.10.0040.00616.81
7.2.00.0080.00617.42
7.1.330.0080.00715.43
7.1.320.0100.00415.50
7.1.310.0080.00515.50
7.1.300.0090.00515.52
7.1.290.0010.01115.57
7.1.280.0050.00815.48
7.1.270.0030.01015.46
7.1.260.0090.00515.57
7.1.250.0070.00415.56
7.1.240.0070.00615.56
7.1.230.0030.00915.42
7.1.220.0030.01015.47
7.1.210.0040.00915.55
7.1.200.0070.00615.56
7.1.190.0070.00515.52
7.1.180.0040.00915.49
7.1.170.0050.00915.55
7.1.160.0050.00915.45
7.1.150.0070.00415.51
7.1.140.0020.01115.46
7.1.130.0070.00415.56
7.1.120.0060.00815.44
7.1.110.0050.00715.51
7.1.100.0050.00716.24
7.1.90.0050.00515.45
7.1.80.0050.00715.49
7.1.70.0080.00515.88
7.1.60.0100.00716.50
7.1.50.0040.01015.93
7.1.40.0070.00415.42
7.1.30.0070.00615.45
7.1.20.0080.00415.43
7.1.10.0090.00515.38
7.1.00.0070.02217.25
7.0.330.0090.00215.21
7.0.320.0030.01015.27
7.0.310.0100.00315.22
7.0.300.0090.00515.18
7.0.290.0060.00515.18
7.0.280.0080.00515.24
7.0.270.0060.00715.23
7.0.260.0050.00715.28
7.0.250.0050.00715.37
7.0.240.0060.00515.46
7.0.230.0080.00515.34
7.0.220.0070.00515.23
7.0.210.0070.00515.25
7.0.200.0060.00615.68
7.0.190.0060.00515.30
7.0.180.0060.00615.15
7.0.170.0050.00715.35
7.0.160.0040.00915.22
7.0.150.0080.00415.20
7.0.140.0080.01917.08
7.0.130.0040.00615.30
7.0.120.0020.00915.29
7.0.110.0040.00715.24
7.0.100.0060.00515.21
7.0.90.0090.00515.17
7.0.80.0080.00615.20
7.0.70.0060.02616.87
7.0.60.0070.02116.95
7.0.50.0080.02017.04
7.0.40.0050.02615.59
7.0.30.0070.02115.59
7.0.20.0060.02415.62
7.0.10.0080.01715.58
7.0.00.0040.02415.59
5.6.400.0110.00014.19
5.6.390.0070.00414.28
5.6.380.0050.00714.23
5.6.370.0020.01114.11
5.6.360.0040.00914.20
5.6.350.0070.00614.14
5.6.340.0040.00714.30
5.6.330.0090.00314.36
5.6.320.0030.01014.34
5.6.310.0060.00814.31
5.6.300.0040.00814.33
5.6.290.0050.00714.06
5.6.280.0050.02415.98
5.6.270.0030.01014.37
5.6.260.0050.00814.23
5.6.250.0100.00414.26
5.6.240.0070.00414.25
5.6.230.0080.00514.14
5.6.220.0090.02215.97
5.6.210.0080.02315.92
5.6.200.0050.02315.97
5.6.190.0050.02716.05
5.6.180.0060.02616.06
5.6.170.0050.02315.94
5.6.160.0060.02316.06
5.6.150.0070.01916.09
5.6.140.0020.02316.09
5.6.130.0020.02615.91
5.6.120.0050.02515.93
5.6.110.0080.02315.96
5.6.100.0060.02316.00
5.6.90.0070.01616.12
5.6.80.0060.02415.76
5.6.70.0070.02015.85
5.6.60.0040.02615.86
5.6.50.0080.02215.74
5.6.40.0080.02315.77
5.6.30.0090.02115.79
5.6.20.0070.02515.85
5.6.10.0080.02215.71
5.6.00.0050.02515.80
5.5.380.0050.00714.37
5.5.370.0040.00814.30
5.5.360.0070.02415.86
5.5.350.0050.02515.80
5.5.340.0080.02315.95
5.5.330.0070.02516.00
5.5.320.0060.02415.84
5.5.310.0060.02515.91
5.5.300.0080.02315.89
5.5.290.0080.02415.86
5.5.280.0060.02315.89
5.5.270.0060.02415.92
5.5.260.0090.02215.94
5.5.250.0060.02415.82
5.5.240.0040.02515.73
5.5.230.0060.02715.80
5.5.220.0100.01915.74
5.5.210.0070.02515.73
5.5.200.0070.02315.72
5.5.190.0080.02415.65
5.5.180.0050.02515.81
5.5.170.0030.01014.15
5.5.160.0050.02315.75
5.5.150.0050.01415.64
5.5.140.0060.01515.63
5.5.130.0050.01715.71
5.5.120.0060.01315.73
5.5.110.0080.01315.69
5.5.100.0030.01615.76
5.5.90.0060.01215.63
5.5.80.0050.01415.67
5.5.70.0070.01315.65
5.5.60.0070.01315.70
5.5.50.0080.01515.70
5.5.40.0070.01615.61
5.5.30.0040.01615.68
5.5.20.0030.02015.69
5.5.10.0050.01215.60
5.5.00.0050.01215.59
5.4.450.0040.02514.35
5.4.440.0070.02414.30
5.4.430.0060.02314.31
5.4.420.0060.02314.38
5.4.410.0030.02414.26
5.4.400.0070.02014.17
5.4.390.0030.02514.13
5.4.380.0050.02114.21
5.4.370.0030.02614.24
5.4.360.0040.02514.24
5.4.350.0090.01714.18
5.4.340.0040.02414.22
5.4.330.0040.00712.52
5.4.320.0070.02214.26
5.4.310.0070.01414.21
5.4.300.0060.01214.25
5.4.290.0060.01214.20
5.4.280.0070.01114.19
5.4.270.0060.01114.15
5.4.260.0050.01314.17
5.4.250.0060.01314.16
5.4.240.0040.01414.14
5.4.230.0070.00914.13
5.4.220.0040.01114.14
5.4.210.0040.01314.17
5.4.200.0070.01014.13
5.4.190.0050.01314.15
5.4.180.0040.01214.07
5.4.170.0050.00814.10
5.4.160.0070.01114.20
5.4.150.0060.01114.17
5.4.140.0060.01613.53
5.4.130.0080.01013.53
5.4.120.0030.01213.51
5.4.110.0050.01113.52
5.4.100.0050.01413.54
5.4.90.0050.01113.49
5.4.80.0020.01413.60
5.4.70.0040.01113.59
5.4.60.0060.00913.48
5.4.50.0020.01213.55
5.4.40.0040.01213.46
5.4.30.0050.01113.49
5.4.20.0060.01113.58
5.4.10.0040.01213.55
5.4.00.0030.01213.32
5.3.290.0060.01813.19
5.3.280.0060.01113.14
5.3.270.0040.01013.21
5.3.260.0040.01613.24
5.3.250.0060.01113.15
5.3.240.0010.01313.19
5.3.230.0030.01313.11
5.3.220.0050.01013.14
5.3.210.0020.01313.19
5.3.200.0050.01313.11
5.3.190.0070.00813.21
5.3.180.0060.01113.26
5.3.170.0020.01313.24
5.3.160.0030.01213.18
5.3.150.0020.01213.26
5.3.140.0050.01213.19
5.3.130.0030.01813.16
5.3.120.0040.01213.15
5.3.110.0050.01113.22
5.3.100.0030.01013.16
5.3.90.0030.01213.15
5.3.80.0030.01413.14
5.3.70.0030.01413.18
5.3.60.0050.01213.12
5.3.50.0050.01113.18
5.3.40.0020.01213.13
5.3.30.0060.01113.21
5.3.20.0050.01013.19
5.3.10.0030.01113.06
5.3.00.0030.01813.06
5.2.170.0020.01613.71
5.2.160.0000.01713.71
5.2.150.0010.01513.56
5.2.140.0050.01813.51
5.2.130.0000.01613.55
5.2.120.0020.01713.66
5.2.110.0020.01613.55
5.2.100.0030.01413.68
5.2.90.0050.01213.68
5.2.80.0020.02413.49
5.2.70.0040.01713.63
5.2.60.0070.02413.62
5.2.50.0050.03313.64
5.2.40.0050.03013.54
5.2.30.0020.03613.50
5.2.20.0020.03613.61
5.2.10.0040.01713.54
5.2.00.0040.02513.41
5.1.60.0040.01712.98
5.1.50.0060.02713.18
5.1.40.0040.02513.30
5.1.30.0020.03013.25
5.1.20.0040.03013.26
5.1.10.0030.02713.06
5.1.00.0070.02213.00
5.0.50.0030.01312.67
5.0.40.0030.01012.67
5.0.30.0070.03312.67
5.0.20.0050.01712.67
5.0.10.0020.01312.67
5.0.00.0050.03012.67
4.4.90.0020.01212.67
4.4.80.0040.01212.67
4.4.70.0020.01512.67
4.4.60.0020.00812.67
4.4.50.0020.01812.67
4.4.40.0020.02012.67
4.4.30.0020.01712.67
4.4.20.0030.01812.67
4.4.10.0020.02212.67
4.4.00.0020.01512.67
4.3.110.0020.01812.67
4.3.100.0030.01812.67
4.3.90.0020.01012.67
4.3.80.0020.01812.67
4.3.70.0020.00812.67
4.3.60.0050.01512.67
4.3.50.0030.01812.67
4.3.40.0020.01712.67
4.3.30.0000.02012.67
4.3.20.0010.01812.67
4.3.10.0030.01512.67
4.3.00.0030.01712.67

preferences:
47.37 ms | 400 KiB | 5 Q