Completed
Push — feature/bench ( ff0490...cd912f )
by Marc
02:48
created

EnumSet32Bench   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 172
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 35
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 172
rs 9

24 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 2
A benchAttachEnumerator() 0 6 2
A benchAttachValue() 0 6 2
A benchDetachEnumerator() 0 6 2
A benchDetachValue() 0 6 2
A benchContainsEnumeratorTrue() 0 6 2
A benchContainsEnumeratorFalse() 0 6 2
A benchContainsValueTrue() 0 6 2
A benchContainsValueFalse() 0 6 2
A benchIterateFull() 0 6 2
A benchIterateEmpty() 0 6 2
A benchCountFull() 0 4 1
A benchCountEmpty() 0 4 1
A benchIsEqual() 0 4 1
A benchIsSubset() 0 4 1
A benchIsSuperset() 0 4 1
A benchUnion() 0 4 1
A benchIntersect() 0 4 1
A benchDiff() 0 4 1
A benchSymDiff() 0 4 1
A benchGetOrdinals() 0 4 1
A benchGetValues() 0 4 1
A benchGetNames() 0 4 1
A benchGetEnumerators() 0 4 1
1
<?php
2
3
namespace MabeEnumBench;
4
5
use MabeEnum\EnumSet;
6
use MabeEnumTest\TestAsset\Enum32;
7
8
/**
9
 * Benchmark of EnumSet used with an enumeration of 32 enumerators.
10
 * (The internal bitset could be both an integer and a binary string)
11
 *
12
 * @BeforeMethods({"init"})
13
 * @Revs(2000)
14
 * @Iterations(25)
15
 */
16
class EnumSet32Bench
17
{
18
    /**
19
     * @var mixed[]
20
     */
21
    private $values;
22
23
    /**
24
     * @var Enum32[]
25
     */
26
    private $enumerators;
27
28
    /**
29
     * @var EnumSet
30
     */
31
    private $emptySet;
32
33
    /**
34
     * @var EnumSet
35
     */
36
    private $fullSet;
37
38
    /**
39
     * Will be called before every subject
40
     */
41
    public function init()
42
    {
43
        $this->values      = Enum32::getValues();
44
        $this->enumerators = Enum32::getEnumerators();
0 ignored issues
show
Documentation Bug introduced by
It seems like \MabeEnumTest\TestAsset\Enum32::getEnumerators() of type array<integer,object<MabeEnum\Enum>> is incompatible with the declared type array<integer,object<Mab...Test\TestAsset\Enum32>> of property $enumerators.

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..

Loading history...
45
46
        $this->emptySet = new EnumSet(Enum32::class);
47
        $this->fullSet  = new EnumSet(Enum32::class);
48
        foreach ($this->enumerators as $enumerator) {
49
            $this->fullSet->attach($enumerator);
50
        }
51
    }
52
53
    public function benchAttachEnumerator()
54
    {
55
        foreach ($this->enumerators as $enumerator) {
56
            $this->emptySet->attach($enumerator);
57
        }
58
    }
59
60
    public function benchAttachValue()
61
    {
62
        foreach ($this->values as $value) {
63
            $this->emptySet->attach($value);
64
        }
65
    }
66
67
    public function benchDetachEnumerator()
68
    {
69
        foreach ($this->enumerators as $enumerator) {
70
            $this->fullSet->detach($enumerator);
71
        }
72
    }
73
74
    public function benchDetachValue()
75
    {
76
        foreach ($this->values as $value) {
77
            $this->fullSet->detach($value);
78
        }
79
    }
80
81
    public function benchContainsEnumeratorTrue()
82
    {
83
        foreach ($this->enumerators as $enumerator) {
84
            $this->fullSet->contains($enumerator);
85
        }
86
    }
87
88
    public function benchContainsEnumeratorFalse()
89
    {
90
        foreach ($this->enumerators as $enumerator) {
91
            $this->fullSet->contains($enumerator);
92
        }
93
    }
94
95
    public function benchContainsValueTrue()
96
    {
97
        foreach ($this->values as $value) {
98
            $this->fullSet->contains($value);
99
        }
100
    }
101
102
    public function benchContainsValueFalse()
103
    {
104
        foreach ($this->values as $value) {
105
            $this->fullSet->contains($value);
106
        }
107
    }
108
109
    public function benchIterateFull()
110
    {
111
        foreach ($this->fullSet as $enumerator) {
112
            $enumerator->getValue();
113
        }
114
    }
115
116
    public function benchIterateEmpty()
117
    {
118
        foreach ($this->emptySet as $enumerator) {
119
            $enumerator->getValue();
120
        }
121
    }
122
123
    public function benchCountFull()
124
    {
125
        $this->fullSet->count();
126
    }
127
128
    public function benchCountEmpty()
129
    {
130
        $this->emptySet->count();
131
    }
132
133
    public function benchIsEqual()
134
    {
135
        $this->fullSet->isEqual($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isEqual() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
136
    }
137
138
    public function benchIsSubset()
139
    {
140
        $this->fullSet->isEqual($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isEqual() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
141
    }
142
143
    public function benchIsSuperset()
144
    {
145
        $this->fullSet->isSuperset($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isSuperset() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
146
    }
147
148
    public function benchUnion()
149
    {
150
        $this->fullSet->union($this->emptySet);
151
    }
152
153
    public function benchIntersect()
154
    {
155
        $this->fullSet->intersect($this->emptySet);
156
    }
157
158
    public function benchDiff()
159
    {
160
        $this->fullSet->diff($this->emptySet);
161
    }
162
163
    public function benchSymDiff()
164
    {
165
        $this->fullSet->symDiff($this->emptySet);
166
    }
167
168
    public function benchGetOrdinals()
169
    {
170
        $this->fullSet->getOrdinals();
171
    }
172
173
    public function benchGetValues()
174
    {
175
        $this->fullSet->getValues();
176
    }
177
178
    public function benchGetNames()
179
    {
180
        $this->fullSet->getNames();
181
    }
182
183
    public function benchGetEnumerators()
184
    {
185
        $this->fullSet->getEnumerators();
186
    }
187
}
188