what puts reduction bucket php server: simplexml json_decode?
i'm starting arise web concentration php i wish spin impossibly renouned me famous rich. :-)
if comes, preference presumably parse api's information xml simplexml json_decode inadequacy app's scalability.
does anyone know approaches some-more fit server?
update: i ran easy exam slight some-more performant. appears json_decode rather faster executing simplexml_load_string. isn't terribly decisive since doesn't exam things scalability indicate processes. finish i simplexml being since the support xpath expressions.
<?php
$xml = file_get_contents('sample.xml');
$json = file_get_contents('sample.js');
$iters = 1000;
// simplexml_load_string
$start_xml = microtime(true);
for ($i = 0; $i < $iters; ++$i) {
$obj = simplexml_load_string($xml, 'simplexmlelement', libxml_nocdata);
}
$end_xml = microtime(true);
// json_decode
$start_json = microtime(true);
for ($i = 0; $i < $iters; ++$i) {
$obj = json_decode($json);
}
$end_json = microtime(true);
?>
<pre>xml elapsed: <?=sprintf('%.4f', ($end_xml - $start_xml))?></pre>
<pre>json elapsed: <?=sprintf('%.4f', ($end_json - $start_json))?></pre>
result:
xml elapsed: 9.9836
json elapsed: 8.3606
Comments
Post a Comment