File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace MabeEnumBench ;
44
5+ use MabeEnum \Enum ;
56use MabeEnumTest \TestAsset \Enum66 ;
7+ use ReflectionClass ;
8+ use ReflectionProperty ;
69
710/**
811 * Benchmark of abstract class Enum tested with enumeration of 66 enumerators.
1720 */
1821class EnumBench
1922{
23+ /**
24+ * @var ReflectionProperty[]
25+ */
26+ private $ enumPropsRefl ;
2027 /**
2128 * @var string[]
2229 */
@@ -42,12 +49,25 @@ class EnumBench
4249 */
4350 public function init ()
4451 {
52+ $ enumRefl = new ReflectionClass (Enum::class);
53+ $ this ->enumPropsRefl = $ enumRefl ->getProperties (ReflectionProperty::IS_STATIC );
54+ foreach ($ this ->enumPropsRefl as $ enumPropRefl ) {
55+ $ enumPropRefl ->setAccessible (true );
56+ }
57+
4558 $ this ->names = Enum66::getNames ();
4659 $ this ->values = Enum66::getValues ();
4760 $ this ->ordinals = Enum66::getOrdinals ();
4861 $ this ->enumerators = Enum66::getEnumerators ();
4962 }
5063
64+ private function resetStaticEnumProps ()
65+ {
66+ foreach ($ this ->enumPropsRefl as $ enumPropRefl ) {
67+ $ enumPropRefl ->setValue ([]);
68+ }
69+ }
70+
5171 public function benchGetName ()
5272 {
5373 foreach ($ this ->enumerators as $ enumerator ) {
@@ -85,6 +105,7 @@ public function benchIsByValue()
85105
86106 public function benchGetConstants ()
87107 {
108+ $ this ->resetStaticEnumProps ();
88109 Enum66::getConstants ();
89110 }
90111
You can’t perform that action at this time.
0 commit comments