Benchmarking Zend_Config_Xml and Zend_Config_Ini


Historically I've always used XML for configuration files, since the format is flexible and the parsing tools mature. Recently I've been considering switching to .ini files for some stuff, as given the simpler format I'd expect the parsing in ZF to be quicker.

This is simple to test of course, so I ran a quick benchmark using the (identical) example configs from the Zend_Config docs. Code below (uses the PEAR benchmarking class):

    get_include_path() . PATH_SEPARATOR .


// Load PEAR profiler class
$profiler = new Benchmark_Profiler(TRUE);

$numTests = 10000;

// Benchmark XML config
for ($x = 0; $x < $numTests; $x++)
    $xml = new Zend_Config_Xml('config.xml');

// Benchmark ini config
for ($x = 0; $x < $numTests; $x++)
    $ini = new Zend_Config_Ini('config.ini');


And the results for 10,000 runs (lower is better):

FormatTime (seconds)

so, in this example parsing the XML file is actually quicker than parsing the same data in ini format.

Just to see how long an individual parse takes, I changed the variable to only parse each file once. The results were then:

FormatTime (seconds)

So with only one parse, ini was quicker! The only explanation I can think of for this is that simplexml is internally caching the file read just in case it needed to reparse the same data. But there is no mention of this in the docs, and it would seem like an odd thing to do in simplexml but not elsewhere.

The sample code and files are in case anyone wants to experiment.

Comments (3) Tags: xml, zend framework, ini


22nd Jul, 2008

From a performance point of view, I would recommend caching the loaded Zend_Cache object and then using your preferred format. Configuration params usually change so infrequently, that you can generally use a really long cache expiry too.



20th Jan, 2009

I am profiling an app of ours and it turned out, that ZendConfigXml consumed over 40% of the overall script runtime. This is definitely a lot and happens due to the internal conversion from XML to Array by using the protected toArray-function.

I then used the Zend
Cache and File-frontend which comes in very handy when using configuration files since you can set a master-file. Any modification to this file automatically refreshes the cache. You don't have to worry about cache expiry.

Well, now that we are using cached configuration objects, the speed was enhanced by a factor of 10!

Conclusion: Even though xml-Config files are nice, be sure to keep em cached since ZendConfigXml isn't very fast.

23rd Apr, 2009

On my machine:
xml 3.0941619873 3.0941619873 1 51.27% Global (1)
ini 2.94120907784 2.94120907784 1 48.73% Global (1)

Add Comment

(Never shown on the site)

(Newlines preserved, format with Markdown)