|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Performance\Hydration; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
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 SingleTableInheritanceInsertPerformanceBench |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var EntityManagerInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $entityManager; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Company\CompanyFixContract[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $fixContracts = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Company\CompanyFlexContract[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $flexContracts = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Company\CompanyFlexUltraContract[] |
|
32
|
|
|
*/ |
|
33
|
|
|
private $ultraContracts = []; |
|
34
|
|
|
|
|
35
|
|
|
public function init() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->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
|
|
|
$person = new Company\CompanyEmployee(); |
|
50
|
|
|
$person->setName('Poor Sales Guy'); |
|
51
|
|
|
$person->setDepartment('Sales'); |
|
52
|
|
|
$person->setSalary(100); |
|
53
|
|
|
$this->entityManager->persist($person); |
|
54
|
|
|
|
|
55
|
|
|
for ($i = 0; $i < 33; $i++) { |
|
56
|
|
|
$this->fixContracts[$i] = new Company\CompanyFixContract(); |
|
57
|
|
|
$this->fixContracts[$i]->setFixPrice(1000); |
|
58
|
|
|
$this->fixContracts[$i]->setSalesPerson($person); |
|
59
|
|
|
$this->fixContracts[$i]->markCompleted(); |
|
60
|
|
|
|
|
61
|
|
|
$this->flexContracts[$i] = new Company\CompanyFlexContract(); |
|
62
|
|
|
$this->flexContracts[$i]->setSalesPerson($person); |
|
63
|
|
|
$this->flexContracts[$i]->setHoursWorked(100); |
|
64
|
|
|
$this->flexContracts[$i]->setPricePerHour(100); |
|
65
|
|
|
$this->flexContracts[$i]->markCompleted(); |
|
66
|
|
|
|
|
67
|
|
|
$this->ultraContracts[$i] = new Company\CompanyFlexUltraContract(); |
|
68
|
|
|
$this->ultraContracts[$i]->setSalesPerson($person); |
|
69
|
|
|
$this->ultraContracts[$i]->setHoursWorked(150); |
|
70
|
|
|
$this->ultraContracts[$i]->setPricePerHour(150); |
|
71
|
|
|
$this->ultraContracts[$i]->setMaxPrice(7000); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function benchInsertFixContracts() |
|
76
|
|
|
{ |
|
77
|
|
|
array_map([$this->entityManager, 'persist'], $this->fixContracts); |
|
78
|
|
|
$this->entityManager->flush(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function benchInsertFlexContracts() |
|
82
|
|
|
{ |
|
83
|
|
|
array_map([$this->entityManager, 'persist'], $this->flexContracts); |
|
84
|
|
|
$this->entityManager->flush(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function benchInsertUltraContracts() |
|
88
|
|
|
{ |
|
89
|
|
|
array_map([$this->entityManager, 'persist'], $this->ultraContracts); |
|
90
|
|
|
$this->entityManager->flush(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function benchInsertAllContracts() |
|
94
|
|
|
{ |
|
95
|
|
|
array_map([$this->entityManager, 'persist'], $this->fixContracts); |
|
96
|
|
|
array_map([$this->entityManager, 'persist'], $this->flexContracts); |
|
97
|
|
|
array_map([$this->entityManager, 'persist'], $this->ultraContracts); |
|
98
|
|
|
$this->entityManager->flush(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|