@@ -50,9 +50,10 @@ class EnumBench
5050 public function init ()
5151 {
5252 $ 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 ) {
5555 $ enumPropRefl ->setAccessible (true );
56+ $ this ->enumPropsRefl [$ enumPropRefl ->getName ()] = $ enumPropRefl ;
5657 }
5758
5859 $ this ->names = Enum66::getNames ();
@@ -61,13 +62,18 @@ public function init()
6162 $ this ->enumerators = Enum66::getEnumerators ();
6263 }
6364
64- private function resetStaticEnumProps ()
65+ private function destructEnumerations ()
6566 {
6667 foreach ($ this ->enumPropsRefl as $ enumPropRefl ) {
6768 $ enumPropRefl ->setValue ([]);
6869 }
6970 }
7071
72+ private function destructEnumerationInstances ()
73+ {
74+ $ this ->enumPropsRefl ['instances ' ]->setValue ([]);
75+ }
76+
7177 public function benchGetName ()
7278 {
7379 foreach ($ this ->enumerators as $ enumerator ) {
@@ -105,7 +111,7 @@ public function benchIsByValue()
105111
106112 public function benchDetectConstants ()
107113 {
108- $ this ->resetStaticEnumProps ();
114+ $ this ->destructEnumerations ();
109115 Enum66::getConstants ();
110116 }
111117
@@ -136,20 +142,68 @@ public function benchByValue()
136142 }
137143 }
138144
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+
139161 public function benchByName ()
140162 {
141163 foreach ($ this ->names as $ name ) {
142164 Enum66::byName ($ name );
143165 }
144166 }
145167
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+
146184 public function benchByOrdinal ()
147185 {
148186 foreach ($ this ->ordinals as $ ord ) {
149187 Enum66::byOrdinal ($ ord );
150188 }
151189 }
152190
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+
153207 public function benchGetByValues ()
154208 {
155209 foreach ($ this ->values as $ value ) {
0 commit comments