Benchmarking Zend_Config_Xml and Zend_Config_Ini

Posted 23:59, 18/7/2008, in Web

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):

<?php
set_include_path(
    get_include_path() . PATH_SEPARATOR .
    '/path/to/zend-framework/library'
);

require('Zend/Loader.php');
Zend_Loader::registerAutoLoad();

// Load PEAR profiler class
require('Benchmark/Profiler.php');
$profiler = new Benchmark_Profiler(TRUE);

$numTests = 10000;

// Benchmark XML config
$profiler->enterSection('xml');
for ($x = 0; $x < $numTests; $x++)
{
    $xml = new Zend_Config_Xml('config.xml');
}
$profiler->leaveSection('xml');

// Benchmark ini config
$profiler->enterSection('ini');
for ($x = 0; $x < $numTests; $x++)
{
    $ini = new Zend_Config_Ini('config.ini');
}
$profiler->leaveSection('ini');

$profiler->stop();
$profiler->display();

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

FormatTime (seconds)
xml4.29669
ini5.6626

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)
xml0.00152
ini0.00122

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 available for download in case anyone wants to experiment.

Comments

Rob
08:07, 22/7/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.

Regards,

Rob...
Sebastian
08:57, 20/1/2009
I am profiling an app of ours and it turned out, that Zend_Config_Xml 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 Zend_Config_Xml isn't very fast.
Jason
21:12, 23/4/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

Or login with OpenID

Search this site
Login
(or login/signup the old fashioned way)
Elsewhere

External URLs/articles that may be of interest:

Adobe releases 64-bit flash player for Linux

Adobe have released an alpha of their 64-bit flash player for Linux (I believe this is the first 64-bit player they've done on any platform, it's not available for Windows or Mac yet). And it works great. It may be an alpha but so far I've found it considerably more stable than the released 32-bit wrapper version. It also uses considerably less CPU power. Easy installation instructions via. this blog entry.

MS Office in the browser

The most interesting thing about this announcement is that MS say the system will work in Firefox and Safari as well as IE. The Microsoft of 10 years ago would have used proprietary IE only code and used it as a way to leverage IE market share.

The Future of Advertising, Branding, Media and Communications

Video of a very interesting talk by Gerd Leonhard on the future of the media industry, and content on the Internet.

Future of web browsing from Mozilla Labs

Some interesting ideas about how web browsing might look in the future (watch the first video).