Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Performance / HydrationPerformanceTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Performance;
4
5 require_once __DIR__ . '/../../TestInit.php';
6
7 use Doctrine\Tests\Mocks\HydratorMockStatement,
8     Doctrine\ORM\Query\ResultSetMapping,
9     Doctrine\ORM\Query;
10
11 /**
12  * Tests to prevent serious performance regressions.
13  *
14  * IMPORTANT: Be sure to run these tests withoug xdebug or similar tools that
15  * seriously degrade performance.
16  *
17  * @author robo
18  * @group performance
19  */
20 class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
21 {
22     /**
23      * Times for comparison:
24      *
25      * [romanb: 10000 rows => 0.7 seconds]
26      *
27      * MAXIMUM TIME: 1 second
28      */
29     public function testSimpleQueryScalarHydrationPerformance10000Rows()
30     {
31         $rsm = new ResultSetMapping;
32         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
33         $rsm->addFieldResult('u', 'u__id', 'id');
34         $rsm->addFieldResult('u', 'u__status', 'status');
35         $rsm->addFieldResult('u', 'u__username', 'username');
36         $rsm->addFieldResult('u', 'u__name', 'name');
37
38         // Faked result set
39         $resultSet = array(
40             //row1
41             array(
42                 'u__id' => '1',
43                 'u__status' => 'developer',
44                 'u__username' => 'romanb',
45                 'u__name' => 'Roman',
46             ),
47             array(
48                 'u__id' => '1',
49                 'u__status' => 'developer',
50                 'u__username' => 'romanb',
51                 'u__name' => 'Roman',
52             ),
53             array(
54                 'u__id' => '2',
55                 'u__status' => 'developer',
56                 'u__username' => 'romanb',
57                 'u__name' => 'Roman',
58             )
59         );
60
61         for ($i = 4; $i < 10000; ++$i) {
62             $resultSet[] = array(
63                 'u__id' => $i,
64                 'u__status' => 'developer',
65                 'u__username' => 'jwage',
66                 'u__name' => 'Jonathan',
67             );
68         }
69
70         $stmt = new HydratorMockStatement($resultSet);
71         $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
72
73         $this->setMaxRunningTime(1);
74         $s = microtime(true);
75         $result = $hydrator->hydrateAll($stmt, $rsm);
76         $e = microtime(true);
77         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
78     }
79
80     /**
81      * Times for comparison:
82      *
83      * [romanb: 10000 rows => 1 second]
84      *
85      * MAXIMUM TIME: 2 seconds
86      */
87     public function testSimpleQueryArrayHydrationPerformance10000Rows()
88     {
89         $rsm = new ResultSetMapping;
90         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
91         $rsm->addFieldResult('u', 'u__id', 'id');
92         $rsm->addFieldResult('u', 'u__status', 'status');
93         $rsm->addFieldResult('u', 'u__username', 'username');
94         $rsm->addFieldResult('u', 'u__name', 'name');
95
96         // Faked result set
97         $resultSet = array(
98             //row1
99             array(
100                 'u__id' => '1',
101                 'u__status' => 'developer',
102                 'u__username' => 'romanb',
103                 'u__name' => 'Roman',
104             ),
105             array(
106                 'u__id' => '1',
107                 'u__status' => 'developer',
108                 'u__username' => 'romanb',
109                 'u__name' => 'Roman',
110             ),
111             array(
112                 'u__id' => '2',
113                 'u__status' => 'developer',
114                 'u__username' => 'romanb',
115                 'u__name' => 'Roman',
116             )
117         );
118
119         for ($i = 4; $i < 10000; ++$i) {
120             $resultSet[] = array(
121                 'u__id' => $i,
122                 'u__status' => 'developer',
123                 'u__username' => 'jwage',
124                 'u__name' => 'Jonathan',
125             );
126         }
127
128         $stmt = new HydratorMockStatement($resultSet);
129         $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
130
131         $this->setMaxRunningTime(2);
132         $s = microtime(true);
133         $result = $hydrator->hydrateAll($stmt, $rsm);
134         $e = microtime(true);
135         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
136     }
137
138     /**
139      * Times for comparison:
140      *
141      * [romanb: 10000 rows => 1.4 seconds]
142      *
143      * MAXIMUM TIME: 3 seconds
144      */
145     public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows()
146     {
147         $rsm = new ResultSetMapping;
148         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
149         $rsm->addJoinedEntityResult(
150                 'Doctrine\Tests\Models\CMS\CmsPhonenumber',
151                 'p',
152                 'u',
153                 'phonenumbers'
154         );
155         $rsm->addFieldResult('u', 'u__id', 'id');
156         $rsm->addFieldResult('u', 'u__status', 'status');
157         $rsm->addFieldResult('u', 'u__username', 'username');
158         $rsm->addFieldResult('u', 'u__name', 'name');
159         $rsm->addScalarResult('sclr0', 'nameUpper');
160         $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
161
162         // Faked result set
163         $resultSet = array(
164             //row1
165             array(
166                 'u__id' => '1',
167                 'u__status' => 'developer',
168                 'u__username' => 'romanb',
169                 'u__name' => 'Roman',
170                 'sclr0' => 'ROMANB',
171                 'p__phonenumber' => '42',
172             ),
173             array(
174                 'u__id' => '1',
175                 'u__status' => 'developer',
176                 'u__username' => 'romanb',
177                 'u__name' => 'Roman',
178                 'sclr0' => 'ROMANB',
179                 'p__phonenumber' => '43',
180             ),
181             array(
182                 'u__id' => '2',
183                 'u__status' => 'developer',
184                 'u__username' => 'romanb',
185                 'u__name' => 'Roman',
186                 'sclr0' => 'JWAGE',
187                 'p__phonenumber' => '91'
188             )
189         );
190
191         for ($i = 4; $i < 10000; ++$i) {
192             $resultSet[] = array(
193                 'u__id' => $i,
194                 'u__status' => 'developer',
195                 'u__username' => 'jwage',
196                 'u__name' => 'Jonathan',
197                 'sclr0' => 'JWAGE' . $i,
198                 'p__phonenumber' => '91'
199             );
200         }
201
202         $stmt = new HydratorMockStatement($resultSet);
203         $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
204
205         $this->setMaxRunningTime(3);
206         $s = microtime(true);
207         $result = $hydrator->hydrateAll($stmt, $rsm);
208         $e = microtime(true);
209         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
210     }
211
212     /**
213      * [romanb: 10000 rows => 1.5 seconds]
214      *
215      * MAXIMUM TIME: 3 seconds
216      */
217     public function testSimpleQueryPartialObjectHydrationPerformance10000Rows()
218     {
219         $rsm = new ResultSetMapping;
220         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
221         $rsm->addFieldResult('u', 'u__id', 'id');
222         $rsm->addFieldResult('u', 'u__status', 'status');
223         $rsm->addFieldResult('u', 'u__username', 'username');
224         $rsm->addFieldResult('u', 'u__name', 'name');
225
226         // Faked result set
227         $resultSet = array(
228             //row1
229             array(
230                 'u__id' => '1',
231                 'u__status' => 'developer',
232                 'u__username' => 'romanb',
233                 'u__name' => 'Roman',
234             ),
235             array(
236                 'u__id' => '1',
237                 'u__status' => 'developer',
238                 'u__username' => 'romanb',
239                 'u__name' => 'Roman',
240             ),
241             array(
242                 'u__id' => '2',
243                 'u__status' => 'developer',
244                 'u__username' => 'romanb',
245                 'u__name' => 'Roman',
246             )
247         );
248
249         for ($i = 4; $i < 10000; ++$i) {
250             $resultSet[] = array(
251                 'u__id' => $i,
252                 'u__status' => 'developer',
253                 'u__username' => 'jwage',
254                 'u__name' => 'Jonathan',
255             );
256         }
257
258         $stmt = new HydratorMockStatement($resultSet);
259         $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
260
261         $this->setMaxRunningTime(3);
262         $s = microtime(true);
263         $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
264         $e = microtime(true);
265         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
266     }
267
268     /**
269      * [romanb: 10000 rows => 3 seconds]
270      *
271      * MAXIMUM TIME: 4.5 seconds
272      */
273     public function testSimpleQueryFullObjectHydrationPerformance10000Rows()
274     {
275         $rsm = new ResultSetMapping;
276         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
277         $rsm->addFieldResult('u', 'u__id', 'id');
278         $rsm->addFieldResult('u', 'u__status', 'status');
279         $rsm->addFieldResult('u', 'u__username', 'username');
280         $rsm->addFieldResult('u', 'u__name', 'name');
281         $rsm->addJoinedEntityResult(
282                 'Doctrine\Tests\Models\CMS\CmsAddress',
283                 'a',
284                 'u',
285                 'address'
286         );
287         $rsm->addFieldResult('a', 'a__id', 'id');
288         //$rsm->addFieldResult('a', 'a__country', 'country');
289         //$rsm->addFieldResult('a', 'a__zip', 'zip');
290         //$rsm->addFieldResult('a', 'a__city', 'city');
291
292         // Faked result set
293         $resultSet = array(
294             //row1
295             array(
296                 'u__id' => '1',
297                 'u__status' => 'developer',
298                 'u__username' => 'romanb',
299                 'u__name' => 'Roman',
300                 'a__id' => '1'
301             )
302         );
303
304         for ($i = 2; $i < 10000; ++$i) {
305             $resultSet[] = array(
306                 'u__id' => $i,
307                 'u__status' => 'developer',
308                 'u__username' => 'jwage',
309                 'u__name' => 'Jonathan',
310                 'a__id' => $i
311             );
312         }
313
314         $stmt = new HydratorMockStatement($resultSet);
315         $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
316
317         $this->setMaxRunningTime(5);
318         $s = microtime(true);
319         $result = $hydrator->hydrateAll($stmt, $rsm);
320         $e = microtime(true);
321         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
322     }
323
324     /**
325      * [romanb: 2000 rows => 0.4 seconds]
326      *
327      * MAXIMUM TIME: 1 second
328      */
329     public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows()
330     {
331         $rsm = new ResultSetMapping;
332         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
333         $rsm->addJoinedEntityResult(
334                 'Doctrine\Tests\Models\CMS\CmsPhonenumber',
335                 'p',
336                 'u',
337                 'phonenumbers'
338         );
339         $rsm->addFieldResult('u', 'u__id', 'id');
340         $rsm->addFieldResult('u', 'u__status', 'status');
341         $rsm->addFieldResult('u', 'u__username', 'username');
342         $rsm->addFieldResult('u', 'u__name', 'name');
343         $rsm->addScalarResult('sclr0', 'nameUpper');
344         $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
345
346         // Faked result set
347         $resultSet = array(
348             //row1
349             array(
350                 'u__id' => '1',
351                 'u__status' => 'developer',
352                 'u__username' => 'romanb',
353                 'u__name' => 'Roman',
354                 'sclr0' => 'ROMANB',
355                 'p__phonenumber' => '42',
356             ),
357             array(
358                 'u__id' => '1',
359                 'u__status' => 'developer',
360                 'u__username' => 'romanb',
361                 'u__name' => 'Roman',
362                 'sclr0' => 'ROMANB',
363                 'p__phonenumber' => '43',
364             ),
365             array(
366                 'u__id' => '2',
367                 'u__status' => 'developer',
368                 'u__username' => 'romanb',
369                 'u__name' => 'Roman',
370                 'sclr0' => 'JWAGE',
371                 'p__phonenumber' => '91'
372             )
373         );
374
375         for ($i = 4; $i < 2000; ++$i) {
376             $resultSet[] = array(
377                 'u__id' => $i,
378                 'u__status' => 'developer',
379                 'u__username' => 'jwage',
380                 'u__name' => 'Jonathan',
381                 'sclr0' => 'JWAGE' . $i,
382                 'p__phonenumber' => '91'
383             );
384         }
385
386         $stmt = new HydratorMockStatement($resultSet);
387         $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
388
389         $this->setMaxRunningTime(1);
390         $s = microtime(true);
391         $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
392         $e = microtime(true);
393         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
394     }
395
396     /**
397      * [romanb: 2000 rows => 0.6 seconds]
398      *
399      * MAXIMUM TIME: 1 second
400      */
401     public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows()
402     {
403         $rsm = new ResultSetMapping;
404         $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
405         $rsm->addJoinedEntityResult(
406                 'Doctrine\Tests\Models\CMS\CmsPhonenumber',
407                 'p',
408                 'u',
409                 'phonenumbers'
410         );
411         $rsm->addFieldResult('u', 'u__id', 'id');
412         $rsm->addFieldResult('u', 'u__status', 'status');
413         $rsm->addFieldResult('u', 'u__username', 'username');
414         $rsm->addFieldResult('u', 'u__name', 'name');
415         $rsm->addScalarResult('sclr0', 'nameUpper');
416         $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
417         $rsm->addJoinedEntityResult(
418                 'Doctrine\Tests\Models\CMS\CmsAddress',
419                 'a',
420                 'u',
421                 'address'
422         );
423         $rsm->addFieldResult('a', 'a__id', 'id');
424
425         // Faked result set
426         $resultSet = array(
427             //row1
428             array(
429                 'u__id' => '1',
430                 'u__status' => 'developer',
431                 'u__username' => 'romanb',
432                 'u__name' => 'Roman',
433                 'sclr0' => 'ROMANB',
434                 'p__phonenumber' => '42',
435                 'a__id' => '1'
436             )
437         );
438
439         for ($i = 2; $i < 2000; ++$i) {
440             $resultSet[] = array(
441                 'u__id' => $i,
442                 'u__status' => 'developer',
443                 'u__username' => 'jwage',
444                 'u__name' => 'Jonathan',
445                 'sclr0' => 'JWAGE' . $i,
446                 'p__phonenumber' => '91',
447                 'a__id' => $i
448             );
449         }
450
451         $stmt = new HydratorMockStatement($resultSet);
452         $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
453
454         $this->setMaxRunningTime(1);
455         $s = microtime(true);
456         $result = $hydrator->hydrateAll($stmt, $rsm);
457         $e = microtime(true);
458         echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
459     }
460 }
461