1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime; |
4
|
|
|
|
5
|
|
|
require_once __DIR__ . '/_files/BenchData.php'; |
6
|
|
|
|
7
|
|
|
use Bdf\Prime\Bench\BenchData; |
8
|
|
|
use Bdf\Prime\Bench\EntityArrayOf; |
9
|
|
|
use Bdf\Prime\Bench\EntityNotTypedArray; |
10
|
|
|
use Bdf\Prime\Cache\ArrayCache; |
11
|
|
|
use Bdf\Prime\Connection\ConnectionConfig; |
|
|
|
|
12
|
|
|
use Bdf\Prime\Repository\EntityRepository; |
13
|
|
|
use Bdf\Prime\Types\ArrayType; |
14
|
|
|
use BenchCaseAdapter; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @Revs(100) |
18
|
|
|
*/ |
19
|
|
|
class TypeBench extends BenchCaseAdapter |
20
|
|
|
{ |
21
|
|
|
const SCALAR_COUNT = 10; |
22
|
|
|
const DATEIME_COUNT = 10; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ServiceLocator |
26
|
|
|
*/ |
27
|
|
|
protected $prime; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var BenchData |
31
|
|
|
*/ |
32
|
|
|
protected $data; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ArrayCache |
36
|
|
|
*/ |
37
|
|
|
protected $cache; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var EntityRepository |
41
|
|
|
*/ |
42
|
|
|
protected $typedRepository; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var EntityRepository |
46
|
|
|
*/ |
47
|
|
|
protected $notTypedRepository; |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function setUp() |
51
|
|
|
{ |
52
|
|
|
$this->cache = new ArrayCache(); |
53
|
|
|
$this->prime = new ServiceLocator(); |
54
|
|
|
$this->prime->connections()->declareConnection('test', BENCH_CONNECTION); |
55
|
|
|
$this->prime->connection('test')->getConfiguration()->getTypes()->register(ArrayType::class, 'array'); |
|
|
|
|
56
|
|
|
Locatorizable::configure($this->prime); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$this->data = new BenchData($this->prime); |
59
|
|
|
$this->data->register([EntityArrayOf::class, EntityNotTypedArray::class]); |
60
|
|
|
|
61
|
|
|
$entities = []; |
62
|
|
|
|
63
|
|
|
for ($i = 0; $i < 100; ++$i) { |
64
|
|
|
$entities[] = new EntityArrayOf([ |
65
|
|
|
'floats' => $this->randArray('double', self::SCALAR_COUNT), |
66
|
|
|
'booleans' => $this->randArray('boolean', self::SCALAR_COUNT), |
67
|
|
|
'dates' => $this->randArray('datetime', self::DATEIME_COUNT), |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$entities[] = new EntityNotTypedArray([ |
71
|
|
|
'floats' => $this->randArray('double', self::SCALAR_COUNT), |
72
|
|
|
'booleans' => $this->randArray('boolean', self::SCALAR_COUNT), |
73
|
|
|
'dates' => array_map(function (\DateTime $dateTime) { return $dateTime->format(\DateTime::ISO8601); }, $this->randArray('datetime', self::DATEIME_COUNT)), |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->data->push($entities); |
78
|
|
|
|
79
|
|
|
$this->typedRepository = $this->prime->repository(EntityArrayOf::class); |
80
|
|
|
$this->notTypedRepository = $this->prime->repository(EntityNotTypedArray::class); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Groups({"array", "read"}) |
85
|
|
|
*/ |
86
|
|
|
public function bench_all_typed() |
87
|
|
|
{ |
88
|
|
|
$this->typedRepository->all(); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Groups({"array", "read"}) |
93
|
|
|
*/ |
94
|
|
|
public function bench_all_not_typed() |
95
|
|
|
{ |
96
|
|
|
$this->notTypedRepository->all(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Groups({"array", "read"}) |
101
|
|
|
*/ |
102
|
|
|
public function bench_all_not_typed_with_cast() |
103
|
|
|
{ |
104
|
|
|
/** @var EntityNotTypedArray $entity */ |
105
|
|
|
foreach ($this->notTypedRepository->all() as $entity) { |
106
|
|
|
$entity->booleans = array_map('boolval', $entity->booleans); |
107
|
|
|
$entity->floats = array_map('doubleval', $entity->floats); |
108
|
|
|
$entity->dates = array_map(function ($str) { return \DateTime::createFromFormat(\DateTime::ISO8601, $str); }, $entity->dates); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @Groups({"array", "insert"}) |
114
|
|
|
*/ |
115
|
|
|
public function bench_insert_typed() |
116
|
|
|
{ |
117
|
|
|
$this->typedRepository->save( |
118
|
|
|
new EntityArrayOf([ |
119
|
|
|
'floats' => $this->randArray('double', self::SCALAR_COUNT), |
120
|
|
|
'booleans' => $this->randArray('boolean', self::SCALAR_COUNT), |
121
|
|
|
'dates' => $this->randArray('datetime', self::DATEIME_COUNT), |
122
|
|
|
]) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @Groups({"array", "insert"}) |
128
|
|
|
*/ |
129
|
|
|
public function bench_insert_not_typed() |
130
|
|
|
{ |
131
|
|
|
$this->notTypedRepository->save( |
132
|
|
|
new EntityNotTypedArray([ |
133
|
|
|
'floats' => $this->randArray('double', self::SCALAR_COUNT), |
134
|
|
|
'booleans' => $this->randArray('boolean', self::SCALAR_COUNT), |
135
|
|
|
'dates' => array_map(function (\DateTime $dateTime) { return $dateTime->format(\DateTime::ISO8601); }, $this->randArray('datetime', self::DATEIME_COUNT)), |
136
|
|
|
]) |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
private function randArray($type, $size) |
141
|
|
|
{ |
142
|
|
|
$array = []; |
143
|
|
|
|
144
|
|
|
for (; $size > 0; --$size) { |
145
|
|
|
$value = rand(0, 100); |
146
|
|
|
|
147
|
|
|
switch ($type) { |
148
|
|
|
case 'double': |
149
|
|
|
$value /= 100; |
150
|
|
|
break; |
151
|
|
|
|
152
|
|
|
case 'boolean': |
153
|
|
|
$value = $value >= 50; |
154
|
|
|
break; |
155
|
|
|
|
156
|
|
|
case 'datetime': |
157
|
|
|
$value = new \DateTime('+'.$value.'days'); |
158
|
|
|
break; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$array[] = $value; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $array; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths