1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MabeEnumBench; |
4
|
|
|
|
5
|
|
|
use MabeEnum\EnumSet; |
6
|
|
|
use MabeEnumTest\TestAsset\Enum66; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Benchmark of EnumSet used with an enumeration of 66 enumerators. |
10
|
|
|
* (The internal bitset have to be a binary string) |
11
|
|
|
* |
12
|
|
|
* @BeforeMethods({"init"}) |
13
|
|
|
* @Revs(2000) |
14
|
|
|
* @Iterations(25) |
15
|
|
|
*/ |
16
|
|
|
class EnumSet66Bench |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var mixed[] |
20
|
|
|
*/ |
21
|
|
|
private $values; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Enum66[] |
25
|
|
|
*/ |
26
|
|
|
private $enumerators; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var EnumSet |
30
|
|
|
*/ |
31
|
|
|
private $emptySet; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var EnumSet |
35
|
|
|
*/ |
36
|
|
|
private $fullSet; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Will be called before every subject |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
public function init() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->values = Enum66::getValues(); |
44
|
|
|
$this->enumerators = Enum66::getEnumerators(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$this->emptySet = new EnumSet(Enum66::class); |
47
|
|
|
$this->fullSet = new EnumSet(Enum66::class); |
48
|
|
|
foreach ($this->enumerators as $enumerator) { |
49
|
|
|
$this->fullSet->attach($enumerator); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function benchAttachEnumeratorOnEmpty() |
54
|
|
|
{ |
55
|
|
|
foreach ($this->enumerators as $enumerator) { |
56
|
|
|
$this->emptySet->attach($enumerator); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function benchAttachValueOnEmpty() |
61
|
|
|
{ |
62
|
|
|
foreach ($this->values as $value) { |
63
|
|
|
$this->emptySet->attach($value); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function benchAttachEnumeratorOnFull() |
68
|
|
|
{ |
69
|
|
|
foreach ($this->enumerators as $enumerator) { |
70
|
|
|
$this->fullSet->attach($enumerator); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function benchAttachValueOnFull() |
75
|
|
|
{ |
76
|
|
|
foreach ($this->values as $value) { |
77
|
|
|
$this->fullSet->attach($value); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function benchDetachEnumeratorOnEmpty() |
82
|
|
|
{ |
83
|
|
|
foreach ($this->enumerators as $enumerator) { |
84
|
|
|
$this->emptySet->detach($enumerator); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function benchDetachValueOnEmpty() |
89
|
|
|
{ |
90
|
|
|
foreach ($this->values as $value) { |
91
|
|
|
$this->emptySet->detach($value); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function benchDetachEnumeratorOnFull() |
96
|
|
|
{ |
97
|
|
|
foreach ($this->enumerators as $enumerator) { |
98
|
|
|
$this->fullSet->detach($enumerator); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function benchDetachValueOnFull() |
103
|
|
|
{ |
104
|
|
|
foreach ($this->values as $value) { |
105
|
|
|
$this->fullSet->detach($value); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function benchContainsEnumeratorTrue() |
110
|
|
|
{ |
111
|
|
|
foreach ($this->enumerators as $enumerator) { |
112
|
|
|
$this->fullSet->contains($enumerator); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function benchContainsValueTrue() |
117
|
|
|
{ |
118
|
|
|
foreach ($this->values as $value) { |
119
|
|
|
$this->fullSet->contains($value); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function benchContainsEnumeratorFalse() |
124
|
|
|
{ |
125
|
|
|
foreach ($this->enumerators as $enumerator) { |
126
|
|
|
$this->fullSet->contains($enumerator); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function benchContainsValueFalse() |
131
|
|
|
{ |
132
|
|
|
foreach ($this->values as $value) { |
133
|
|
|
$this->fullSet->contains($value); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function benchIterateFull() |
138
|
|
|
{ |
139
|
|
|
foreach ($this->fullSet as $enumerator) { |
140
|
|
|
$enumerator->getValue(); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function benchIterateEmpty() |
145
|
|
|
{ |
146
|
|
|
foreach ($this->emptySet as $enumerator) { |
147
|
|
|
$enumerator->getValue(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function benchCountFull() |
152
|
|
|
{ |
153
|
|
|
$this->fullSet->count(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function benchCountEmpty() |
157
|
|
|
{ |
158
|
|
|
$this->emptySet->count(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function benchIsEqual() |
162
|
|
|
{ |
163
|
|
|
$this->fullSet->isEqual($this->fullSet); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function benchIsSubset() |
167
|
|
|
{ |
168
|
|
|
$this->fullSet->isEqual($this->fullSet); |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function benchIsSuperset() |
172
|
|
|
{ |
173
|
|
|
$this->fullSet->isSuperset($this->fullSet); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function benchUnion() |
177
|
|
|
{ |
178
|
|
|
$this->fullSet->union($this->emptySet); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function benchIntersect() |
182
|
|
|
{ |
183
|
|
|
$this->fullSet->intersect($this->emptySet); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function benchDiff() |
187
|
|
|
{ |
188
|
|
|
$this->fullSet->diff($this->emptySet); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function benchSymDiff() |
192
|
|
|
{ |
193
|
|
|
$this->fullSet->symDiff($this->emptySet); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function benchGetOrdinals() |
197
|
|
|
{ |
198
|
|
|
$this->fullSet->getOrdinals(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function benchGetValues() |
202
|
|
|
{ |
203
|
|
|
$this->fullSet->getValues(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function benchGetNames() |
207
|
|
|
{ |
208
|
|
|
$this->fullSet->getNames(); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function benchGetEnumerators() |
212
|
|
|
{ |
213
|
|
|
$this->fullSet->getEnumerators(); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.