|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Performance\Hydration; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Internal\Hydration\ObjectHydrator; |
|
6
|
|
|
use Doctrine\ORM\Query; |
|
7
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
|
8
|
|
|
use Doctrine\Performance\EntityManagerFactory; |
|
9
|
|
|
use Doctrine\Tests\Mocks\HydratorMockStatement; |
|
10
|
|
|
use Doctrine\Tests\Models\CMS\CmsAddress; |
|
11
|
|
|
use Doctrine\Tests\Models\CMS\CmsUser; |
|
12
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @BeforeMethods({"init"}) |
|
16
|
|
|
*/ |
|
17
|
|
|
final class SimpleQueryFullObjectHydrationPerformanceBench |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ObjectHydrator |
|
21
|
|
|
*/ |
|
22
|
|
|
private $hydrator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ResultSetMapping |
|
26
|
|
|
*/ |
|
27
|
|
|
private $rsm; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var HydratorMockStatement |
|
31
|
|
|
*/ |
|
32
|
|
|
private $stmt; |
|
33
|
|
|
|
|
34
|
|
|
public function init() |
|
35
|
|
|
{ |
|
36
|
|
|
$resultSet = [ |
|
37
|
|
|
[ |
|
38
|
|
|
'u__id' => '1', |
|
39
|
|
|
'u__status' => 'developer', |
|
40
|
|
|
'u__username' => 'romanb', |
|
41
|
|
|
'u__name' => 'Roman', |
|
42
|
|
|
'a__id' => '1' |
|
43
|
|
|
] |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
for ($i = 2; $i < 10000; ++$i) { |
|
47
|
|
|
$resultSet[] = [ |
|
48
|
|
|
'u__id' => $i, |
|
49
|
|
|
'u__status' => 'developer', |
|
50
|
|
|
'u__username' => 'jwage', |
|
51
|
|
|
'u__name' => 'Jonathan', |
|
52
|
|
|
'a__id' => $i |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->stmt = new HydratorMockStatement($resultSet); |
|
57
|
|
|
$this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([])); |
|
58
|
|
|
$this->rsm = new ResultSetMapping; |
|
59
|
|
|
|
|
60
|
|
|
$this->rsm->addEntityResult(CmsUser::class, 'u'); |
|
61
|
|
|
$this->rsm->addFieldResult('u', 'u__id', 'id'); |
|
62
|
|
|
$this->rsm->addFieldResult('u', 'u__status', 'status'); |
|
63
|
|
|
$this->rsm->addFieldResult('u', 'u__username', 'username'); |
|
64
|
|
|
$this->rsm->addFieldResult('u', 'u__name', 'name'); |
|
65
|
|
|
$this->rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); |
|
66
|
|
|
$this->rsm->addFieldResult('a', 'a__id', 'id'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function benchHydration() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->hydrator->hydrateAll($this->stmt, $this->rsm); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|