Completed
Push — feature/74 ( 60c27e...f551d9 )
by Marc
04:30
created

EnumBench   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 32
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 149
rs 9.6
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
 * @BeforeMethods({"init"})
11
 * @Revs(2500)
12
 * @Iterations(25)
13
 */
14
class EnumBench
15
{
16
    /**
17
     * @var string[]
18
     */
19
    private $names;
20
21
    /**
22
     * @var mixed[]
23
     */
24
    private $values;
25
26
    /**
27
     * @var int[]
28
     */
29
    private $ordinals;
30
31
    /**
32
     * @var Enum66[]
33
     */
34
    private $enumerators;
35
36
    /**
37
     * Will be called before every subject
38
     */
39
    public function init()
40
    {
41
        $this->names       = Enum66::getNames();
42
        $this->values      = Enum66::getValues();
43
        $this->ordinals    = Enum66::getOrdinals();
44
        $this->enumerators = Enum66::getEnumerators();
45
    }
46
47
    public function benchGetName()
48
    {
49
        foreach ($this->enumerators as $enumerator) {
50
            $enumerator->getName();
51
        }
52
    }
53
54
    public function benchGetValue()
55
    {
56
        foreach ($this->enumerators as $enumerator) {
57
            $enumerator->getValue();
58
        }
59
    }
60
61
    public function benchGetOrdinal()
62
    {
63
        foreach ($this->enumerators as $enumerator) {
64
            $enumerator->getOrdinal();
65
        }
66
    }
67
68
    public function benchIsByEnumerator()
69
    {
70
        foreach ($this->enumerators as $enumerator) {
71
            $enumerator->is($enumerator);
72
        }
73
    }
74
75
    public function benchIsByValue()
76
    {
77
        foreach ($this->enumerators as $enumerator) {
78
            $enumerator->is($enumerator->getValue());
79
        }
80
    }
81
82
    public function benchGetConstants()
83
    {
84
        Enum66::getConstants();
85
    }
86
87
    public function benchGetValues()
88
    {
89
        Enum66::getValues();
90
    }
91
92
    public function benchGetNames()
93
    {
94
        Enum66::getNames();
95
    }
96
97
    public function benchGetOrdinals()
98
    {
99
        Enum66::getOrdinals();
100
    }
101
102
    public function benchGetEnumerators()
103
    {
104
        Enum66::getEnumerators();
105
    }
106
107
    public function benchByValue()
108
    {
109
        foreach ($this->values as $value) {
110
            Enum66::byValue($value);
111
        }
112
    }
113
114
    public function benchByName()
115
    {
116
        foreach ($this->names as $name) {
117
            Enum66::byName($name);
118
        }
119
    }
120
121
    public function benchByOrdinal()
122
    {
123
        foreach ($this->ordinals as $ord) {
124
            Enum66::byOrdinal($ord);
125
        }
126
    }
127
128
    public function benchGetByValues()
129
    {
130
        foreach ($this->values as $value) {
131
            Enum66::get($value);
132
        }
133
    }
134
135
    public function benchGetByEnumerator()
136
    {
137
        foreach ($this->enumerators as $enumerator) {
138
            Enum66::get($enumerator);
139
        }
140
    }
141
142
    public function benchGetByCallStatic()
143
    {
144
        foreach ($this->names as $name) {
145
            Enum66::$name();
146
        }
147
    }
148
149
    public function benchHasByEnumerator()
150
    {
151
        foreach ($this->enumerators as $enumerator) {
152
            Enum66::has($enumerator);
153
        }
154
    }
155
156
    public function benchHasByValue()
157
    {
158
        foreach ($this->values as $value) {
159
            Enum66::has($value);
160
        }
161
    }
162
}
163