Doctrine2はPDOの3倍以上遅い – Benchmarking PDO, mysqli, Doctrine2

PHP

概要

背景:
Doctrine2のパフォーマンスが良くなったらしいので、ベンチマークしてみた。
ちなみに、2年前にベンチマークを取ったときには、Doctrine1はPDOの約3倍遅かった

結論:
今もなお、Doctrine2はPDOに比べて3倍以上遅かった。

ベンチマーク結果

doctrine_pdo_benchmark

測定環境

Debian6.0 + PHP5.4 + MySQL5.5 localhost

スキーマ

> desc item;
+---------+----------------------+------+-----+---------------------+-----------------------------+
| Field   | Type                 | Null | Key | Default             | Extra                       |
+---------+----------------------+------+-----+---------------------+-----------------------------+
| id      | int(10) unsigned     | NO   | PRI | NULL                | auto_increment              |
| user_id | int(10) unsigned     | NO   | MUL | NULL                |                             |
| item_id | smallint(5) unsigned | NO   |     | NULL                |                             |
| num     | int(11)              | NO   |     | 0                   |                             |
| mtime   | timestamp            | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP |
| ctime   | datetime             | NO   |     | 0000-00-00 00:00:00 |                             |
+---------+----------------------+------+-----+---------------------+-----------------------------+
6 rows in set (0.00 sec)

発行しているクエリーはこちら。
業務上、Selectが重要なので、シンプルなSelectだけ。

<?php
require_once "bootstrap.php";

class Doctrine2Benchmarks
{
    public function selectByPrimaryKey()
    {
        global $entityManager;
        $dql = "SELECT i FROM Item i WHERE i.id = 1";
        $items = $entityManager->createQuery($dql)->getScalarResult();
   }

    public function selectByMultiplePrimaryKey()
    {
        global $entityManager;
        $dql = "SELECT i FROM Item i WHERE i.id in (1,2,3)";
        $items = $entityManager->createQuery($dql)->getScalarResult();
    }

    public function selectByIndex()
    {
        global $entityManager;
        $dql = "SELECT i FROM Item i WHERE i.user_id = 100";
        $items = $entityManager->createQuery($dql)->getScalarResult();
    }
}

まとめ

Doctrine2はPDOに比べて3倍以上遅かった。

コメント