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

Unknown
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...

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:

Future of web browsing from Mozilla Labs

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

PHP - Architecture, Scalability, and Security

Slides from Rasmus' OSCON talk, once again some interesting ways of tweaking server performance to get the most out of PHP apps.

New Rails documentation site

Lack of a decent manual has always been a big problem for Rails (an API reference is not a manual!) A number of projects have sprung up in the last year or so trying to make up for this, this new one is the best I've seen so far, so hopefully it will gain some traction.

bbc.co.uk moving to Zend Framework

The BBC are updating their perl/SSI based backend to a platform using Java for the backend and Zend Framework for the frontend.