Performance Test #1

Description: What is the best way to load one or many configuration data? Loading data from database, from an XML file, from INI file or from SESSIONS??? Below you can see the results generated on the fly.

MEMORY INCREASE: how much memory consumes each method
EXECUTION TIME: how much time it needs for each method to be executed

Conclusions: As the results shows below, as many times as you run this tests saving configuration data in sessions is the fastest way with a slightly difference in memory usage which increases a bit compares to loading from INI file. Loading the configuration settings of your application in sessions saves resources and improves performance. But at what cost?

Memory Usage (Initial): 673544 bytes

DATA LOADING
METHOD
MEMORY INCREASE
(bytes)
EXECUTION TIME
(seconds)
Database 1520 0.069546
INI 1096 0.003963
XML 2216 0.000609
Sessions 1104 5.00000000003E-6
[1] Loading data from database:
		$connect = mysql_connect('localhost', 'username', 'password');
		mysql_select_db('database', $connect);	
		$data = Array();
		$q = mysql_query('select * from config');
		$row = mysql_fetch_object($q);
		while($row){
			$data[$row->id][$row->name] = $row->value;
			$row = mysql_fetch_object($q);
		}
		
		
		#Database:
		CREATE TABLE `config` (
	  		`name` varchar(150) DEFAULT NULL,
	  		`value` varchar(250) DEFAULT NULL
		) ENGINE=MyISAM DEFAULT CHARSET=latin1;
		
		Data:	
		INSERT INTO `config` VALUES ('autoload', 'true');
		INSERT INTO `config` VALUES ('show_captions', 'false');
		INSERT INTO `config` VALUES ('language_preference', 'en');
		INSERT INTO `config` VALUES ('allow_only_ip', '10.2.10.159');
		INSERT INTO `config` VALUES ('templates_path', '/var/www/templates_c');
		
		
[2] Loading data from INI file:
		$ini_array = parse_ini_file("myconfig.ini", true);
		$data = $ini_array['config'];
			
		#INI File:
		[config]
		autoload = true
		show_captions = false
		language_preference =	en
		allow_only_ip = 10.2.10.159
		templates_path = /var/www/templates_c
		
[3] Loading data from Sessions:
		$data = $_SESSION['config'];    
					
		#Sessions setting up data
		if(!isset($_SESSION['colors']) || !is_array($_SESSION['colors']) || sizeof($_SESSION['colors']) <= 0){
		$_SESSION['config'] = Array('autoload' => 'true',
									'show_captions' => 'false',
									'language_preference' =>	'en',
									'allow_only_ip' => '10.2.10.159',
									'templates_path' => '/var/www/templates_c');
		}
		
[4] Loading data from XML file:
		$xml = new MyXml();
		$xml->src = "myconfig.xml";
		$xmlData = $xml->loadXml();
		$data = $xmlData->application[0];
		
		#XML File:
		<?xml version="1.0" encoding="UTF-8"?>
		<configuration>
			<application>
				<config>
					<name>autoload</name>
					<value>true</value>
				</config>	
				<config>
					<name>show_captions</name>
					<value>false</value>
				</config>	
				<config>
					<name>language_preference</name>
					<value>en</value>
				</config>	
				<config>
					<name>allow_only_ip</name>
					<value>10.2.10.159</value>
				</config>	
				<config>
					<name>templates_path</name>
					<value>/var/www/templates_c</value>
				</config>		
			</application>
		</configuration>