Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Performance / PersisterPerformanceTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Performance;
4
5 use Doctrine\ORM\Tools\SchemaTool;
6 use Doctrine\ORM\Query;
7 use Doctrine\Tests\Models\CMS\CmsUser;
8 use Doctrine\Tests\Models\CMS\CmsPhonenumber;
9 use Doctrine\Tests\Models\CMS\CmsAddress;
10 use Doctrine\Tests\Models\CMS\CmsGroup;
11 use Doctrine\Tests\Models\CMS\CmsArticle;
12 use Doctrine\Tests\Models\CMS\CmsComment;
13
14 require_once __DIR__ . '/../../TestInit.php';
15
16 /**
17  * @group performance
18  */
19 class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
20 {
21     protected function setUp()
22     {
23         $this->useModelSet('cms');
24         parent::setUp();
25     }
26
27     public function testFindCmsArticle()
28     {
29         $author = new CmsUser();
30         $author->name = "beberlei";
31         $author->status = "active";
32         $author->username = "beberlei";
33         $this->_em->persist($author);
34
35         $ids = array();
36         for ($i = 0; $i < 100; $i++) {
37             $article = new CmsArticle();
38             $article->text = "foo";
39             $article->topic = "bar";
40             $article->user = $author;
41             $this->_em->persist($article);
42             $ids[] = $article;
43         }
44         $this->_em->flush();
45         $this->_em->clear();
46
47         $start = microtime(true);
48         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
49         echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
50
51         $this->_em->clear();
52
53         $start = microtime(true);
54         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
55         echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
56
57         $this->_em->clear();
58
59         $start = microtime(true);
60         for ($i = 0; $i < 100; $i++) {
61             $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
62         }
63         echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
64
65         $this->_em->clear();
66
67         $start = microtime(true);
68         for ($i = 0; $i < 100; $i++) {
69             $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
70         }
71         echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
72     }
73
74     public function testFindCmsGroup()
75     {
76         for ($i = 0; $i < 100; $i++) {
77             $group = new CmsGroup();
78             $group->name = "foo" . $i;
79             $this->_em->persist($group);
80         }
81         $this->_em->flush();
82         $this->_em->clear();
83
84         $start = microtime(true);
85         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
86         echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
87
88         $this->_em->clear();
89
90         $start = microtime(true);
91         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
92         echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
93     }
94
95     public function testFindCmsUser()
96     {
97         for ($i = 0; $i < 100; $i++) {
98             $user = new CmsUser();
99             $user->name = "beberlei";
100             $user->status = "active";
101             $user->username = "beberlei".$i;
102             $this->_em->persist($user);
103         }
104
105         $this->_em->flush();
106         $this->_em->clear();
107
108         $start = microtime(true);
109         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
110         echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
111
112         $this->_em->clear();
113
114         $start = microtime(true);
115         $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
116         echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
117     }
118 }
119
120
121