1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Performance\Hydration; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
6
|
|
|
use Doctrine\Performance\EntityManagerFactory; |
7
|
|
|
use Doctrine\Tests\Models\Company; |
8
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @BeforeMethods({"init"}) |
12
|
|
|
*/ |
13
|
|
|
final class SingleTableInheritanceHydrationPerformanceBench |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ObjectRepository |
17
|
|
|
*/ |
18
|
|
|
private $contractsRepository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ObjectRepository |
22
|
|
|
*/ |
23
|
|
|
private $fixContractsRepository; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var ObjectRepository |
27
|
|
|
*/ |
28
|
|
|
private $flexContractRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ObjectRepository |
32
|
|
|
*/ |
33
|
|
|
private $ultraContractRepository; |
34
|
|
|
|
35
|
|
|
public function init() |
36
|
|
|
{ |
37
|
|
|
$entityManager = EntityManagerFactory::getEntityManager([ |
38
|
|
|
Company\CompanyPerson::class, |
39
|
|
|
Company\CompanyEmployee::class, |
40
|
|
|
Company\CompanyManager::class, |
41
|
|
|
Company\CompanyOrganization::class, |
42
|
|
|
Company\CompanyEvent::class, |
43
|
|
|
Company\CompanyAuction::class, |
44
|
|
|
Company\CompanyRaffle::class, |
45
|
|
|
Company\CompanyCar::class, |
46
|
|
|
Company\CompanyContract::class, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$this->contractsRepository = $entityManager->getRepository(Company\CompanyContract::class); |
50
|
|
|
$this->fixContractsRepository = $entityManager->getRepository(Company\CompanyFixContract::class); |
51
|
|
|
$this->flexContractRepository = $entityManager->getRepository(Company\CompanyFlexContract::class); |
52
|
|
|
$this->ultraContractRepository = $entityManager->getRepository(Company\CompanyFlexUltraContract::class); |
53
|
|
|
|
54
|
|
|
$person = new Company\CompanyEmployee(); |
55
|
|
|
$person->setName('Poor Sales Guy'); |
56
|
|
|
$person->setDepartment('Sales'); |
57
|
|
|
$person->setSalary(100); |
58
|
|
|
$entityManager->persist($person); |
59
|
|
|
|
60
|
|
|
for ($i = 0; $i < 33; $i++) { |
61
|
|
|
$fixContract = new Company\CompanyFixContract(); |
62
|
|
|
$flexContract = new Company\CompanyFlexContract(); |
63
|
|
|
$ultraContract = new Company\CompanyFlexUltraContract(); |
64
|
|
|
|
65
|
|
|
$fixContract->setFixPrice(1000); |
66
|
|
|
$fixContract->setSalesPerson($person); |
67
|
|
|
$fixContract->markCompleted(); |
68
|
|
|
|
69
|
|
|
$flexContract->setSalesPerson($person); |
70
|
|
|
$flexContract->setHoursWorked(100); |
71
|
|
|
$flexContract->setPricePerHour(100); |
72
|
|
|
$flexContract->markCompleted(); |
73
|
|
|
|
74
|
|
|
$ultraContract->setSalesPerson($person); |
75
|
|
|
$ultraContract->setHoursWorked(150); |
76
|
|
|
$ultraContract->setPricePerHour(150); |
77
|
|
|
$ultraContract->setMaxPrice(7000); |
78
|
|
|
|
79
|
|
|
$entityManager->persist($fixContract); |
80
|
|
|
$entityManager->persist($flexContract); |
81
|
|
|
$entityManager->persist($ultraContract); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$entityManager->flush(); |
85
|
|
|
$entityManager->clear(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function benchHydrateFixContracts() |
89
|
|
|
{ |
90
|
|
|
$this->fixContractsRepository->findAll(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function benchHydrateFlexContracts() |
94
|
|
|
{ |
95
|
|
|
$this->flexContractRepository->findAll(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function benchHydrateUltraContracts() |
99
|
|
|
{ |
100
|
|
|
$this->ultraContractRepository->findAll(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function benchHydrateAllContracts() |
104
|
|
|
{ |
105
|
|
|
$this->contractsRepository->findAll(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|