1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MabeEnumBench; |
4
|
|
|
|
5
|
|
|
use MabeEnumTest\TestAsset\Enum66; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Benchmark of abstract class Enum tested with enumeration of 66 enumerators. |
9
|
|
|
* |
10
|
|
|
* @BeforeClassMethods({"initClass"}) |
11
|
|
|
* @Revs(2500) |
12
|
|
|
* @Iterations(25) |
13
|
|
|
*/ |
14
|
|
|
class EnumBench |
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 Enum66[] |
38
|
|
|
*/ |
39
|
|
|
private static $enumerators; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Initialize class |
43
|
|
|
*/ |
44
|
|
|
public static function initClass() |
45
|
|
|
{ |
46
|
|
|
// initialize the enum to make sure the initialization process |
47
|
|
|
// will not effect the benchmark |
48
|
|
|
self::$constants = Enum66::getConstants(); |
49
|
|
|
self::$names = Enum66::getNames(); |
|
|
|
|
50
|
|
|
self::$values = Enum66::getValues(); |
51
|
|
|
self::$ordinals = Enum66::getOrdinals(); |
52
|
|
|
self::$enumerators = Enum66::getEnumerators(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function benchGetName() |
56
|
|
|
{ |
57
|
|
|
foreach (self::$enumerators as $enumerator) { |
58
|
|
|
$enumerator->getName(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function benchGetValue() |
63
|
|
|
{ |
64
|
|
|
foreach (self::$enumerators as $enumerator) { |
65
|
|
|
$enumerator->getValue(); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function benchGetOrdinal() |
70
|
|
|
{ |
71
|
|
|
foreach (self::$enumerators as $enumerator) { |
72
|
|
|
$enumerator->getOrdinal(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function benchIsByEnumerator() |
77
|
|
|
{ |
78
|
|
|
foreach (self::$enumerators as $enumerator) { |
79
|
|
|
$enumerator->is($enumerator); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function benchIsByValue() |
84
|
|
|
{ |
85
|
|
|
foreach (self::$enumerators as $enumerator) { |
86
|
|
|
$enumerator->is($enumerator->getValue()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function benchGetConstants() |
91
|
|
|
{ |
92
|
|
|
Enum66::getConstants(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function benchGetValues() |
96
|
|
|
{ |
97
|
|
|
Enum66::getValues(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function benchGetNames() |
101
|
|
|
{ |
102
|
|
|
Enum66::getNames(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function benchGetOrdinals() |
106
|
|
|
{ |
107
|
|
|
Enum66::getOrdinals(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function benchGetEnumerators() |
111
|
|
|
{ |
112
|
|
|
Enum66::getEnumerators(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function benchByValue() |
116
|
|
|
{ |
117
|
|
|
foreach (self::$values as $value) { |
118
|
|
|
Enum66::byValue($value); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function benchByName() |
123
|
|
|
{ |
124
|
|
|
foreach (self::$names as $name) { |
125
|
|
|
Enum66::byName($name); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function benchByOrdinal() |
130
|
|
|
{ |
131
|
|
|
foreach (self::$ordinals as $ord) { |
132
|
|
|
Enum66::byOrdinal($ord); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function benchGetByValues() |
137
|
|
|
{ |
138
|
|
|
foreach (self::$values as $value) { |
139
|
|
|
Enum66::get($value); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function benchGetByEnumerator() |
144
|
|
|
{ |
145
|
|
|
foreach (self::$enumerators as $enumerator) { |
146
|
|
|
Enum66::get($enumerator); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function benchGetByCallStatic() |
151
|
|
|
{ |
152
|
|
|
foreach (self::$names as $name) { |
153
|
|
|
Enum66::$name(); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function benchHasByEnumerator() |
158
|
|
|
{ |
159
|
|
|
foreach (self::$enumerators as $enumerator) { |
160
|
|
|
Enum66::has($enumerator); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function benchHasByValue() |
165
|
|
|
{ |
166
|
|
|
foreach (self::$values as $value) { |
167
|
|
|
Enum66::has($value); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
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..