3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $iterations = 10000; $json = <<<JSON { "status": "ok", "items": [ { "title": "Some valuable title", "descr": "Another valuable description, much longer", "url": "http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf", "bid": 0.1 }, { "title": "Some valuable title", "descr": "Another valuable description, much longer", "url": "http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf", "bid": 0.1 }, { "title": "Some valuable title", "descr": "Another valuable description, much longer", "url": "http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf", "bid": 0.1 }, { "title": "Some valuable title", "descr": "Another valuable description, much longer", "url": "http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf", "bid": 0.1 }, { "title": "Some valuable title", "descr": "Another valuable description, much longer", "url": "http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf", "bid": 0.1 } ] } JSON; $xml = <<<XML <?xml version='1.0'?> <response> <status>ok</status> <items> <item> <title>Some valuable title</title> <descr>Another valuable description, much longer</descr> <url> <![CDATA[http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf]]></url> <bid>0.1</bid> </item> <item> <title>Some valuable title</title> <descr>Another valuable description, much longer</descr> <url> <![CDATA[http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf]]></url> <bid>0.1</bid> </item> <item> <title>Some valuable title</title> <descr>Another valuable description, much longer</descr> <url> <![CDATA[http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf]]></url> <bid>0.1</bid> </item> <item> <title>Some valuable title</title> <descr>Another valuable description, much longer</descr> <url> <![CDATA[http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf]]></url> <bid>0.1</bid> </item> <item> <title>Some valuable title</title> <descr>Another valuable description, much longer</descr> <url> <![CDATA[http://alonglonglnog.com/?var=qp34rasjdnfkamdso;ilaksdnfa;sldjngaskdnfa;sdlkfjasd;lkfasdf]]></url> <bid>0.1</bid> </item> </items> </response> XML; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $obj = json_encode($json); } $jsonTime = microtime(true) - $start; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $xmlObj = simplexml_load_string($xml); } $xmlTime = microtime(true) - $start; printf("json is faster in %.2 times.", $xmlTime / $jsonTime);
based on kWDKg
Output for 5.2.0 - 7.1.0
json is faster in times.
Output for 5.0.0 - 5.1.1, 5.1.3 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/8FK0J on line 88
Process exited with code 255.
Output for 5.1.2
Fatal error: Call to undefined function json_encode() in /in/8FK0J on line 90
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/8FK0J on line 88
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/8FK0J on line 88
Process exited with code 255.
Output for 4.4.2
Fatal error: Call to undefined function: json_encode() in /in/8FK0J on line 90
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/8FK0J on line 88