провёл для себя эксперимент выявить каким способом

Oct 22, 2014

провёл для себя эксперимент выявить каким способом быстрее достать данные, например достать id=185 и его tv параметр price0 привожу листинги кодов 1)

$begin_time = time() - 1272000000 + floatval(microtime());

$q1 = $modx->newQuery('modTemplateVarResource');

$q1->where(array('tmplvarid' => '19'));

$q1->select(array('modTemplateVarResource.*'));

$q1->limit(1000);   

$q1->prepare();

$q1->stmt->execute();

$tvres = $q1->stmt->fetchAll(PDO::FETCH_ASSOC);

//print_r($tvres);

//-------resources------------

$q = $modx->newQuery('modResource');

$q->where(array(

    'context_key' => 'web'

));

$q->select(array(

   'modResource.*'

));

$q->limit(1000);   

$q->prepare();

$q->stmt->execute();

$result = $q->stmt->fetchAll(PDO::FETCH_ASSOC);

$id = 185;//ресурс который ищем

foreach($result as $res){

    if($res[id] == $id ){

        foreach($tvres as $tv){

            if($tv[contentid] == $id){

            echo $res[pagetitle] . "\n";

            echo $tv[value] . "\n";

            }

        }

    }

}

$end_time = time() - 1272000000 + floatval(microtime()) - $begin_time;

echo $end_time;

время потраченое 0.055360972881317 второй листинг 2)

$begin_time = time() - 1272000000 + floatval(microtime());

$outHtmlAll='';

$modx->setLogLevel(3);

$namespace = 'shopmodx';

if(!$response = $modx->runProcessor('web/getdata', 

array( "limit" => 1000

 // Параметры

), array(

    'processors_path'   => $modx->getObject('modNamespace', $namespace)->getCorePath().'processors/',        

))){

    print "Не удалось выполнить процессор";    

    return;

}

$res0 = $response->getResponse();

//print_r($res0);

$id = 185;//ресурс который ищем

echo $res0[object][$id][pagetitle]. "\n";

echo $res0[object][$id][tvs][price0][value]. "\n";

$end_time = time() - 1272000000 + floatval(microtime()) - $begin_time;

echo $end_time . "\n";

время потраченое 0.47229799628258