Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Pascal may be an admirable language for teaching beginners how to program
store_config/load_config, и не задаваться вопросом, какой из стапятисот предложенных авторами языка методов мне выбрать.config->switchInstance('additional');
runMethod();
config->switchInstance('main');
function runMethod(){
$cfg = config::getInstance();
...
}
function config($file)
{
return simplexml_load_file($file);
}
function config($file) {
$xml = simplexml_load_file($file);
$array = array();
foreach($xml as $key => $value) {
$array[$key] = (string)$value;
}
return $array;
}
$seconds = sqrt($size / 10000);$time1 = microtime(true);
$time2 = $time1;
$calls = 0;
while ($time2 <= $time1 + $seconds) {
unserialize($string);
$time2 = microtime(true);
$calls++;
}
($time2 - $time1)*1000 / $callsamount of enrites: 10000
data size: 387860
calls: 182
serialize: 5.4978132247925 ms
data size: 268961
calls: 90
json: 11.220910814073 ms
amount of enrites: 50000
data size: 1983594
calls: 73
serialize: 30.974479121049 ms
data size: 1344695
calls: 39
json: 57.372336890754 ms
amount of enrites: 240000
data size: 9703391
calls: 18
serialize: 276.30117538543 ms
data size: 6454491
calls: 18
json: 279.90789217722 ms$time = new DateTime();
echo "Start:".$time->getTimestamp().PHP_EOL;
$mc= new Memcache;
$mc->connect('localhost', 11211);
$key = "_config1000";
for ($i=0; $i<10000; $i++) {
$config = $mc->get($key);
if (!$config) {
$config = parse_ini_file('test.ini');
$mc->add($key, serialize($config));
}
}
$time = new DateTime();
echo "End:".$time->getTimestamp().PHP_EOL;
$mc->add($key, serialize($config));$time = new DateTime();
echo "Start:".$time->getTimestamp().PHP_EOL;
require_once 'Rediska.php';
for ($i=0; $i<100000; $i++) {
$options = array(
'namespace' => 'Auto3_',
'servers' => array(
array('host' => '127.0.0.1',
'port' => '6379'
)
)
);
$rediska = new Rediska($options);
$keyn = "__conf1000";
$key = new Rediska_Key($keyn);
$config = $key->getValue($keyn);
if (!$config) {
$config = parse_ini_file('test.ini');
$key->setValue($config);
}
}
$time = new DateTime();
echo "End:".$time->getTimestamp().PHP_EOL;
Самые быстрые настройки для PHP-скриптов