Answer the question
In order to leave comments, you need to log in
Why is Yii1 query builder faster than Yii2?
I decided to compare the performance of query execution. It is not clear to me why the code was executed twice as slowly on Yii2.
Yii1 (0.56 sec):
$command = Yii::app()->db->createCommand();
$command->select('id');
$command->from('task');
$command->limit = 4000;
$result = $command->queryAll();
$data = [];
$start = microtime(true);
foreach($result as $a){
$command = Yii::app()->db->createCommand();
$command->from('task AS T');
$command->where('id = :id', [':id' => $a['id']]);
$command->limit = 1;
$data[] = $command->queryRow();
}
$stop = microtime(true);
$time = $stop - $start;
print_r($time);exit();
$query = new Query();
$query->select('id');
$query->from('task');
$query->limit(4000);
$result = $query->all();
$data = [];
$start = microtime(true);
foreach($result as $a){
$query = new Query();
$query->from('task AS T');
$query->where('id = :id', [':id' => $a['id']]);
$query->limit(1);
$data[] = $query->one();
}
$stop = microtime(true);
$time = $stop - $start;
print_r($time);exit();
Answer the question
In order to leave comments, you need to log in
I didn’t understand something, in your tests it says that yii2 is faster)
Yii1 (0.97 sec):
Yii2 (0.56 sec):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question