So I have this minimal model
class Potd extends \Phalcon\Mvc\Model
{
/**
* @var int $id
*/
public $id;
}
and this code:
$items = Potd::find([
'mode' => 2,
'order' => 'date', // DESC
]);
echo count($items);
It works ok, but it take about 150 ms.l, while this plain code:
$st = $this->di->get('db')->prepare('SELECT * FROM potd WHERE mode = :mode ORDER BY :order');
$st->execute(['mode' => 2, 'order' => 'date']);
$res = $st->fetchAll();
$items = [];
foreach ($res as $item) {
$model = new Potd();
$model->id = $item['id'];
$items[] = $model;
}
echo count($items);
runs in about 35 ms.
Actually, Phalcon is only 16% faster than gigantic symfony2 with doctrine in this particular task. Here is apache benchmark results ab -c 20 -n 1000 localhost
:
Phalcon: 23.29 RPS
Symfony2: 19.80 RPS
Plain PDO: 131.18 RPS
I understand that Phalcon is a framework and it should be slower than plain php, but 5 times slower? Also, I don't know what exactly going on inside find
, but it looks pretty simple for me: construct query, fetch items, fill objects. So, the question: am I doing something wrong?