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

EnumMapench::benchOffsetExistsEnumeratorTrue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace MabeEnumBench;
4
5
use MabeEnum\EnumMap;
6
use MabeEnumTest\TestAsset\Enum66;
7
8
/**
9
 * Benchmark of EnumMap used with an enumeration of 66 enumerators.
10
 *
11
 * @BeforeMethods({"init"})
12
 * @Revs(2000)
13
 * @Iterations(25)
14
 */
15
class EnumMapench
16
{
17
    /**
18
     * @var mixed[]
19
     */
20
    private $values;
21
22
    /**
23
     * @var Enum66[]
24
     */
25
    private $enumerators;
26
27
    /**
28
     * @var EnumMap
29
     */
30
    private $emptyMap;
31
32
    /**
33
     * @var EnumMap
34
     */
35
    private $fullMap;
36
37
    /**
38
     * Will be called before every subject
39
     */
40 View Code Duplication
    public function init()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->values      = Enum66::getValues();
43
        $this->enumerators = Enum66::getEnumerators();
0 ignored issues
show
Documentation Bug introduced by
It seems like \MabeEnumTest\TestAsset\Enum66::getEnumerators() of type array<integer,object<MabeEnum\Enum>> is incompatible with the declared type array<integer,object<Mab...Test\TestAsset\Enum66>> 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...
44
45
        $this->emptyMap = new EnumMap(Enum66::class);
46
        $this->fullMap  = new EnumMap(Enum66::class);
47
        foreach ($this->enumerators as $i => $enumerator) {
48
            $this->fullMap->offsetSet($enumerator, $i);
49
        }
50
    }
51
52
    public function benchOffsetSetEnumerator()
53
    {
54
        foreach ($this->enumerators as $enumerator) {
55
            $this->emptyMap->offsetSet($enumerator);
56
        }
57
    }
58
59
    public function benchOffsetSetValue()
60
    {
61
        foreach ($this->values as $value) {
62
            $this->emptyMap->offsetSet($value);
63
        }
64
    }
65
66
    public function benchOffsetUnsetEnumerator()
67
    {
68
        foreach ($this->enumerators as $enumerator) {
69
            $this->fullMap->offsetUnset($enumerator);
70
        }
71
    }
72
73
    public function benchOffsetUnsetValue()
74
    {
75
        foreach ($this->values as $value) {
76
            $this->fullMap->offsetUnset($value);
77
        }
78
    }
79
80
    public function benchOffsetExistsEnumeratorTrue()
81
    {
82
        foreach ($this->enumerators as $enumerator) {
83
            $this->fullMap->offsetExists($enumerator);
84
        }
85
    }
86
87
    public function benchOffsetExistsEnumeratorFalse()
88
    {
89
        foreach ($this->enumerators as $enumerator) {
90
            $this->fullMap->offsetExists($enumerator);
91
        }
92
    }
93
94
    public function benchOffsetExistsValueTrue()
95
    {
96
        foreach ($this->values as $value) {
97
            $this->fullMap->offsetExists($value);
98
        }
99
    }
100
101
    public function benchOffsetExistsValueFalse()
102
    {
103
        foreach ($this->values as $value) {
104
            $this->fullMap->offsetExists($value);
105
        }
106
    }
107
108
    public function benchIterateFull()
109
    {
110
        foreach ($this->fullMap as $enumerator => $_) {
111
            $enumerator->getValue();
0 ignored issues
show
Bug introduced by
The method getValue cannot be called on $enumerator (of type integer|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
        }
113
    }
114
115
    public function benchIterateEmpty()
116
    {
117
        foreach ($this->emptyMap as $enumerator => $_) {
118
            $enumerator->getValue();
0 ignored issues
show
Bug introduced by
The method getValue cannot be called on $enumerator (of type integer|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
        }
120
    }
121
122
    public function benchCountFull()
123
    {
124
        $this->fullMap->count();
125
    }
126
127
    public function benchCountEmpty()
128
    {
129
        $this->emptyMap->count();
130
    }
131
}
132