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):
<?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):
| Format | Time (seconds) |
|---|---|
| xml | 4.29669 |
| ini | 5.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:
| Format | Time (seconds) |
|---|---|
| xml | 0.00152 |
| ini | 0.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
08:07, 22/7/2008
Regards,
Rob...
Add comment