|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* GpsLab component. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Peter Gribanov <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2017, Peter Gribanov |
|
8
|
|
|
* @license http://opensource.org/licenses/MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace GpsLab\Component\Enum\Bench\Compare; |
|
12
|
|
|
|
|
13
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcExp; |
|
14
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcRef; |
|
15
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\DefRef; |
|
16
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcHappyTypes; |
|
17
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMarcMabe; |
|
18
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMyClabs; |
|
19
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\DefMarcMabe; |
|
20
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Iterations; |
|
21
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Revs; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @Revs(2500) |
|
25
|
|
|
* @Iterations(25) |
|
26
|
|
|
*/ |
|
27
|
|
|
class AllOperationCompareEnumBench implements CompareEnumBench |
|
28
|
|
|
{ |
|
29
|
|
View Code Duplication |
public function benchReflectionEnum() |
|
30
|
|
|
{ |
|
31
|
|
|
$a = AbcRef::A(); |
|
32
|
|
|
$a->equals(AbcRef::A()); |
|
33
|
|
|
|
|
34
|
|
|
$b = AbcRef::B(); |
|
35
|
|
|
$b->equals(AbcRef::A()); |
|
36
|
|
|
|
|
37
|
|
|
$c = AbcRef::C(); |
|
38
|
|
|
$z = (string) $c; |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
AbcRef::choices(); |
|
41
|
|
|
AbcRef::values(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
public function benchReflectionEnumNoMagic() |
|
45
|
|
|
{ |
|
46
|
|
|
$d = DefRef::byValue(DefRef::D); |
|
47
|
|
|
$d->equals(DefRef::byValue(DefRef::D)); |
|
48
|
|
|
|
|
49
|
|
|
$e = DefRef::byValue(DefRef::E); |
|
50
|
|
|
$e->equals(DefRef::byValue(DefRef::D)); |
|
51
|
|
|
|
|
52
|
|
|
$f = DefRef::byValue(DefRef::F); |
|
53
|
|
|
$z = (string) $f; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
DefRef::choices(); |
|
56
|
|
|
DefRef::values(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
public function benchExplicitEnum() |
|
60
|
|
|
{ |
|
61
|
|
|
$a = AbcExp::byValue(AbcExp::A); |
|
62
|
|
|
$a->equals(AbcExp::byValue(AbcExp::A)); |
|
63
|
|
|
|
|
64
|
|
|
$b = AbcExp::byValue(AbcExp::B); |
|
65
|
|
|
$b->equals(AbcExp::byValue(AbcExp::A)); |
|
66
|
|
|
|
|
67
|
|
|
$c = AbcExp::byValue(AbcExp::C); |
|
68
|
|
|
$e = (string) $c; |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
AbcExp::choices(); |
|
71
|
|
|
AbcExp::values(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
View Code Duplication |
public function benchMyCLabsEnum() |
|
75
|
|
|
{ |
|
76
|
|
|
$a = AbcMyClabs::A(); |
|
77
|
|
|
$a->equals(AbcMyClabs::A()); |
|
78
|
|
|
|
|
79
|
|
|
$b = AbcMyClabs::B(); |
|
80
|
|
|
$b->equals(AbcMyClabs::A()); |
|
81
|
|
|
|
|
82
|
|
|
$c = AbcMyClabs::C(); |
|
83
|
|
|
$z = (string) $c; |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
AbcMyClabs::choices(); |
|
86
|
|
|
AbcMyClabs::values(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
public function benchMabeEnum() |
|
90
|
|
|
{ |
|
91
|
|
|
$a = AbcMarcMabe::A(); |
|
92
|
|
|
$a->is(AbcMarcMabe::A()); |
|
93
|
|
|
|
|
94
|
|
|
$b = AbcMarcMabe::B(); |
|
95
|
|
|
$b->is(AbcMarcMabe::A()); |
|
96
|
|
|
|
|
97
|
|
|
$c = AbcMarcMabe::C(); |
|
98
|
|
|
$z = (string) $c; |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
AbcMarcMabe::choices(); |
|
101
|
|
|
AbcMarcMabe::values(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
public function benchMabeNoMagicEnum() |
|
105
|
|
|
{ |
|
106
|
|
|
$d = DefMarcMabe::byValue(DefMarcMabe::D); |
|
107
|
|
|
$d->is(DefMarcMabe::byValue(DefMarcMabe::D)); |
|
108
|
|
|
|
|
109
|
|
|
$e = DefMarcMabe::byValue(DefMarcMabe::E); |
|
110
|
|
|
$e->is(DefMarcMabe::byValue(DefMarcMabe::D)); |
|
111
|
|
|
|
|
112
|
|
|
$f = DefMarcMabe::byValue(DefMarcMabe::F); |
|
113
|
|
|
$z = (string) $f; |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
DefMarcMabe::choices(); |
|
116
|
|
|
DefMarcMabe::values(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
View Code Duplication |
public function benchHappyTypesEnum() |
|
120
|
|
|
{ |
|
121
|
|
|
$a = AbcHappyTypes::A(); |
|
122
|
|
|
$a->equals(AbcHappyTypes::A()); |
|
123
|
|
|
|
|
124
|
|
|
$b = AbcHappyTypes::B(); |
|
125
|
|
|
$b->equals(AbcHappyTypes::A()); |
|
126
|
|
|
|
|
127
|
|
|
$c = AbcHappyTypes::C(); |
|
128
|
|
|
$z = (string) $c; |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
AbcHappyTypes::choices(); |
|
131
|
|
|
AbcHappyTypes::values(); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.