1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MabeEnumBench; |
4
|
|
|
|
5
|
|
|
use MabeEnum\EnumSet; |
6
|
|
|
use MabeEnumTest\TestAsset\Enum32; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @BeforeClassMethods({"initClass"}) |
10
|
|
|
* @BeforeMethods({"init"}) |
11
|
|
|
* @Revs(1000) |
12
|
|
|
* @Iterations(20) |
13
|
|
|
*/ |
14
|
|
|
class EnumSet32Bench |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private static $constants; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string[] |
23
|
|
|
*/ |
24
|
|
|
private static $names; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var mixed[] |
28
|
|
|
*/ |
29
|
|
|
private static $values; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int[] |
33
|
|
|
*/ |
34
|
|
|
private static $ordinals; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Enum32[] |
38
|
|
|
*/ |
39
|
|
|
private static $enumerators; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var EnumSet |
43
|
|
|
*/ |
44
|
|
|
private $emptySet; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var EnumSet |
48
|
|
|
*/ |
49
|
|
|
private $fullSet; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Initialize class |
53
|
|
|
*/ |
54
|
|
|
public static function initClass() |
55
|
|
|
{ |
56
|
|
|
// initialize the enum to make sure the initialization process |
57
|
|
|
// will not effect the benchmark |
58
|
|
|
self::$constants = Enum32::getConstants(); |
59
|
|
|
self::$names = Enum32::getNames(); |
|
|
|
|
60
|
|
|
self::$values = Enum32::getValues(); |
61
|
|
|
self::$ordinals = Enum32::getOrdinals(); |
62
|
|
|
self::$enumerators = Enum32::getEnumerators(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Initialize object |
67
|
|
|
*/ |
68
|
|
|
public function init() |
69
|
|
|
{ |
70
|
|
|
$this->emptySet = new EnumSet(Enum32::class); |
71
|
|
|
$this->fullSet = new EnumSet(Enum32::class); |
72
|
|
|
foreach (self::$enumerators as $enumerator) { |
73
|
|
|
$this->fullSet->attach($enumerator); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function benchAttachEnumeratorOnEmpty() |
78
|
|
|
{ |
79
|
|
|
foreach (self::$enumerators as $enumerator) { |
80
|
|
|
$this->emptySet->attach($enumerator); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function benchAttachValueOnEmpty() |
85
|
|
|
{ |
86
|
|
|
foreach (self::$values as $value) { |
87
|
|
|
$this->emptySet->attach($value); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function benchAttachEnumeratorOnFull() |
92
|
|
|
{ |
93
|
|
|
foreach (self::$enumerators as $enumerator) { |
94
|
|
|
$this->fullSet->attach($enumerator); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function benchAttachValueOnFull() |
99
|
|
|
{ |
100
|
|
|
foreach (self::$values as $value) { |
101
|
|
|
$this->fullSet->attach($value); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function benchDetachEnumeratorOnEmpty() |
106
|
|
|
{ |
107
|
|
|
foreach (self::$enumerators as $enumerator) { |
108
|
|
|
$this->emptySet->detach($enumerator); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function benchDetachValueOnEmpty() |
113
|
|
|
{ |
114
|
|
|
foreach (self::$values as $value) { |
115
|
|
|
$this->emptySet->detach($value); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function benchDetachEnumeratorOnFull() |
120
|
|
|
{ |
121
|
|
|
foreach (self::$enumerators as $enumerator) { |
122
|
|
|
$this->fullSet->detach($enumerator); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function benchDetachValueOnFull() |
127
|
|
|
{ |
128
|
|
|
foreach (self::$values as $value) { |
129
|
|
|
$this->fullSet->detach($value); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function benchContainsEnumeratorTrue() |
134
|
|
|
{ |
135
|
|
|
foreach (self::$enumerators as $enumerator) { |
136
|
|
|
$this->fullSet->contains($enumerator); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function benchContainsValueTrue() |
141
|
|
|
{ |
142
|
|
|
foreach (self::$values as $value) { |
143
|
|
|
$this->fullSet->contains($value); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function benchContainsEnumeratorFalse() |
148
|
|
|
{ |
149
|
|
|
foreach (self::$enumerators as $enumerator) { |
150
|
|
|
$this->fullSet->contains($enumerator); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function benchContainsValueFalse() |
155
|
|
|
{ |
156
|
|
|
foreach (self::$values as $value) { |
157
|
|
|
$this->fullSet->contains($value); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function benchIterateFull() |
162
|
|
|
{ |
163
|
|
|
foreach ($this->fullSet as $enumerator) { |
164
|
|
|
$enumerator->key(); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function benchIterateEmpty() |
169
|
|
|
{ |
170
|
|
|
foreach ($this->emptySet as $enumerator) { |
171
|
|
|
$enumerator->key(); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function benchCountFull() |
176
|
|
|
{ |
177
|
|
|
$this->fullSet->count(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function benchCountEmpty() |
181
|
|
|
{ |
182
|
|
|
$this->emptySet->count(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function benchIsEqual() |
186
|
|
|
{ |
187
|
|
|
$this->fullSet->isEqual($this->fullSet); |
|
|
|
|
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function benchIsSubset() |
191
|
|
|
{ |
192
|
|
|
$this->fullSet->isEqual($this->fullSet); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function benchIsSuperset() |
196
|
|
|
{ |
197
|
|
|
$this->fullSet->isSuperset($this->fullSet); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function benchUnion() |
201
|
|
|
{ |
202
|
|
|
$this->fullSet->union($this->emptySet); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function benchIntersect() |
206
|
|
|
{ |
207
|
|
|
$this->fullSet->intersect($this->emptySet); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function benchDiff() |
211
|
|
|
{ |
212
|
|
|
$this->fullSet->diff($this->emptySet); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function benchSymDiff() |
216
|
|
|
{ |
217
|
|
|
$this->fullSet->symDiff($this->emptySet); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function benchGetOrdinals() |
221
|
|
|
{ |
222
|
|
|
$this->fullSet->getOrdinals(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function benchGetValues() |
226
|
|
|
{ |
227
|
|
|
$this->fullSet->getValues(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function benchGetNames() |
231
|
|
|
{ |
232
|
|
|
$this->fullSet->getNames(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function benchGetEnumerators() |
236
|
|
|
{ |
237
|
|
|
$this->fullSet->getEnumerators(); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..