3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); class XML { var $parser; #a reference to the XML parser var $document; #the entire XML structure built up so far var $current; #a pointer to the current item - what is this var $parent; #a pointer to the current parent - the parent will be an array var $parents; #an array of the most recent parent at each level var $last_opened_tag; function XML($data=null){ $this->parser = xml_parser_create(); xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "open", "close"); xml_set_character_data_handler($this->parser, "data"); # register_shutdown_function(array(&$this, 'destruct')); } function destruct(){ xml_parser_free($this->parser); } function parse($data){ $this->document = array(); $this->parent = &$this->document; $this->parents = array(); $this->last_opened_tag = NULL; xml_parse($this->parser, $data); return $this->document; } function open($parser, $tag, $attributes){ #echo "Opening tag $tag<br>\n"; $this->data = ""; $this->last_opened_tag = $tag; #tag is a string if(array_key_exists($tag, $this->parent)){ #echo "There's already an instance of '$tag' at the current level ($level)<br>\n"; if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric #need to make sure they're numeric (account for attributes) $key = count_numeric_items($this->parent[$tag]); #echo "There are $key instances: the keys are numeric.<br>\n"; }else{ #echo "There is only one instance. Shifting everything around<br>\n"; $temp = &$this->parent[$tag]; unset($this->parent[$tag]); $this->parent[$tag][0] = &$temp; if(array_key_exists("$tag attr", $this->parent)){ #shift the attributes around too if they exist $temp = &$this->parent["$tag attr"]; unset($this->parent["$tag attr"]); $this->parent[$tag]["0 attr"] = &$temp; } $key = 1; } $this->parent = &$this->parent[$tag]; }else{ $key = $tag; } if($attributes){ $this->parent["$key attr"] = $attributes; } $this->parent[$key] = array(); $this->parent = &$this->parent[$key]; array_unshift($this->parents, &$this->parent); } function data($parser, $data){ #echo "Data is '", htmlspecialchars($data), "'<br>\n"; if($this->last_opened_tag != NULL){ $this->data .= $data; } } function close($parser, $tag){ #echo "Close tag $tag<br>\n"; if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_shift($this->parents); $this->parent = &$this->parents[0]; } }

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)
5.4.320.0230.03019.31
5.4.310.0300.03719.03
5.4.300.0230.04719.11
5.4.290.0200.05318.99
5.4.280.0370.02018.99
5.4.270.0270.04718.99
5.4.260.0170.03719.31
5.4.250.0000.04018.97
5.4.240.0100.03319.07
5.4.230.0170.04019.21
5.4.220.0300.04018.78
5.4.210.0230.03718.98
5.4.200.0200.03718.85
5.4.190.0270.03018.85
5.4.180.0170.04018.82
5.4.170.0300.05718.79
5.4.160.0030.03719.03
5.4.150.0000.04319.29
5.4.140.1300.04316.50
5.4.130.1730.03716.52
5.4.120.1730.04716.34
5.4.110.1600.04016.45
5.4.100.1770.04716.37
5.4.90.1430.03716.59
5.4.80.1470.03316.57
5.4.70.1600.02316.46
5.4.60.1470.03716.52
5.4.50.1470.03716.43
5.4.40.1700.03016.55
5.4.30.1700.03316.37
5.4.20.1600.02716.54
5.4.10.1570.03716.37
5.4.00.1430.03715.80
5.3.290.1700.04314.61
5.3.280.1700.03714.64
5.3.270.1470.03314.79
5.3.260.1570.04314.62
5.3.250.1730.04714.55
5.3.240.1570.04714.64
5.3.230.1530.03714.55
5.3.220.1630.03314.63
5.3.210.1570.03014.67
5.3.200.1600.04714.54
5.3.190.1400.04014.57
5.3.180.1730.04314.60
5.3.170.1730.04314.71
5.3.160.1700.04714.84
5.3.150.1500.03314.52
5.3.140.1770.03714.55
5.3.130.1730.04314.73
5.3.120.1700.04314.71
5.3.110.1670.03714.82
5.3.100.1700.04714.12
5.3.90.1570.04314.07
5.3.80.1600.04313.95
5.3.70.1500.03713.95
5.3.60.1730.04314.06
5.3.50.0700.05014.06
5.3.40.0000.07313.90
5.3.30.0030.06014.16
5.3.20.0070.07013.70
5.3.10.1730.03713.61
5.3.00.1730.03713.78
5.2.170.1470.03711.11
5.2.160.1430.03311.10
5.2.150.1500.04011.08
5.2.140.1270.03711.15
5.2.130.1230.01711.36
5.2.120.1400.04011.21
5.2.110.1270.02711.11
5.2.100.1070.02711.22
5.2.90.1270.03011.19
5.2.80.0730.03311.04
5.2.70.0000.03711.21
5.2.60.0070.03311.23
5.2.50.0470.05711.06
5.2.40.1070.02310.94
5.2.30.1000.03011.08
5.2.20.1070.03311.05
5.2.10.1170.03010.80
5.2.00.1030.02310.68
5.1.60.1170.03310.13
5.1.50.1300.02310.16
5.1.40.0970.0309.91
5.1.30.1070.02710.33
5.1.20.1030.02710.46
5.1.10.1070.02310.18
5.1.00.1030.0279.96
5.0.50.0530.0238.56
5.0.40.0600.0238.56
5.0.30.0400.0338.56
5.0.20.0530.0178.56
5.0.10.0530.0278.56
5.0.00.0430.0278.56
4.4.90.0000.0178.56
4.4.80.0030.0138.56
4.4.70.0000.0208.56
4.4.60.0030.0178.56
4.4.50.0000.0178.56
4.4.40.0000.0238.56
4.4.30.0030.0138.56
4.4.20.0130.0238.56
4.4.10.0470.0208.56
4.4.00.0530.0238.56
4.3.110.0570.0178.56
4.3.100.0630.0238.56
4.3.90.0570.0138.56
4.3.80.0500.0238.56
4.3.70.0500.0178.56
4.3.60.0570.0208.56
4.3.50.0500.0178.56
4.3.40.0530.0208.56
4.3.30.0230.0178.56
4.3.20.0230.0178.56
4.3.10.0230.0178.56
4.3.00.0270.0138.56

preferences:
142.29 ms | 1394 KiB | 7 Q