@@ -50,9 +50,10 @@ class EnumBench
50
50
public function init ()
51
51
{
52
52
$ enumRefl = new ReflectionClass (Enum::class);
53
- $ this -> enumPropsRefl = $ enumRefl ->getProperties (ReflectionProperty::IS_STATIC );
54
- foreach ($ this -> enumPropsRefl as $ enumPropRefl ) {
53
+ $ enumPropsRefl = $ enumRefl ->getProperties (ReflectionProperty::IS_STATIC );
54
+ foreach ($ enumPropsRefl as $ enumPropRefl ) {
55
55
$ enumPropRefl ->setAccessible (true );
56
+ $ this ->enumPropsRefl [$ enumPropRefl ->getName ()] = $ enumPropRefl ;
56
57
}
57
58
58
59
$ this ->names = Enum66::getNames ();
@@ -61,13 +62,18 @@ public function init()
61
62
$ this ->enumerators = Enum66::getEnumerators ();
62
63
}
63
64
64
- private function resetStaticEnumProps ()
65
+ private function destructEnumerations ()
65
66
{
66
67
foreach ($ this ->enumPropsRefl as $ enumPropRefl ) {
67
68
$ enumPropRefl ->setValue ([]);
68
69
}
69
70
}
70
71
72
+ private function destructEnumerationInstances ()
73
+ {
74
+ $ this ->enumPropsRefl ['instances ' ]->setValue ([]);
75
+ }
76
+
71
77
public function benchGetName ()
72
78
{
73
79
foreach ($ this ->enumerators as $ enumerator ) {
@@ -105,7 +111,7 @@ public function benchIsByValue()
105
111
106
112
public function benchDetectConstants ()
107
113
{
108
- $ this ->resetStaticEnumProps ();
114
+ $ this ->destructEnumerations ();
109
115
Enum66::getConstants ();
110
116
}
111
117
@@ -136,20 +142,68 @@ public function benchByValue()
136
142
}
137
143
}
138
144
145
+ public function benchByValueAndInitialize ()
146
+ {
147
+ foreach ($ this ->values as $ value ) {
148
+ $ this ->destructEnumerations ();
149
+ Enum66::byValue ($ value );
150
+ }
151
+ }
152
+
153
+ public function benchByValueAndInstantiate ()
154
+ {
155
+ $ this ->destructEnumerationInstances ();
156
+ foreach ($ this ->values as $ value ) {
157
+ Enum66::byValue ($ value );
158
+ }
159
+ }
160
+
139
161
public function benchByName ()
140
162
{
141
163
foreach ($ this ->names as $ name ) {
142
164
Enum66::byName ($ name );
143
165
}
144
166
}
145
167
168
+ public function benchByNameAndInitialize ()
169
+ {
170
+ foreach ($ this ->names as $ name ) {
171
+ $ this ->destructEnumerations ();
172
+ Enum66::byName ($ name );
173
+ }
174
+ }
175
+
176
+ public function benchByNameAndInstantiate ()
177
+ {
178
+ $ this ->destructEnumerationInstances ();
179
+ foreach ($ this ->names as $ name ) {
180
+ Enum66::byName ($ name );
181
+ }
182
+ }
183
+
146
184
public function benchByOrdinal ()
147
185
{
148
186
foreach ($ this ->ordinals as $ ord ) {
149
187
Enum66::byOrdinal ($ ord );
150
188
}
151
189
}
152
190
191
+ public function benchByOrdinalAndInitialize ()
192
+ {
193
+ foreach ($ this ->ordinals as $ ord ) {
194
+ $ this ->destructEnumerations ();
195
+ Enum66::byOrdinal ($ ord );
196
+ }
197
+ }
198
+
199
+ public function benchByOrdinalAndInstantiate ()
200
+ {
201
+ $ this ->destructEnumerationInstances ();
202
+ foreach ($ this ->ordinals as $ ord ) {
203
+ Enum66::byOrdinal ($ ord );
204
+ }
205
+ }
206
+
153
207
public function benchGetByValues ()
154
208
{
155
209
foreach ($ this ->values as $ value ) {
0 commit comments