1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types=1); |
20
|
|
|
|
21
|
|
|
namespace ProxyManagerBench; |
22
|
|
|
|
23
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
24
|
|
|
use ProxyManagerTestAsset\ClassWithMixedProperties; |
25
|
|
|
use ProxyManagerTestAsset\ClassWithPrivateProperties; |
26
|
|
|
use ProxyManagerTestAsset\ClassWithProtectedProperties; |
27
|
|
|
use ProxyManagerTestAsset\ClassWithPublicProperties; |
28
|
|
|
use ReflectionProperty; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Benchmark that provides baseline results for simple object state interactions |
32
|
|
|
* |
33
|
|
|
* @author Marco Pivetta <[email protected]> |
34
|
|
|
* @license MIT |
35
|
|
|
* |
36
|
|
|
* @BeforeMethods({"setUp"}) |
37
|
|
|
*/ |
38
|
|
|
class BaselinePropertyAccessBench |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var ClassWithPrivateProperties |
42
|
|
|
*/ |
43
|
|
|
private $privateProperties; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ReflectionProperty |
47
|
|
|
*/ |
48
|
|
|
private $accessPrivateProperty; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var ClassWithProtectedProperties |
52
|
|
|
*/ |
53
|
|
|
private $protectedProperties; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var ReflectionProperty |
57
|
|
|
*/ |
58
|
|
|
private $accessProtectedProperty; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var ClassWithPublicProperties |
62
|
|
|
*/ |
63
|
|
|
private $publicProperties; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var ClassWithMixedProperties |
67
|
|
|
*/ |
68
|
|
|
private $mixedProperties; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var ReflectionProperty |
72
|
|
|
*/ |
73
|
|
|
private $accessMixedPropertiesPrivate; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var ReflectionProperty |
77
|
|
|
*/ |
78
|
|
|
private $accessMixedPropertiesProtected; |
79
|
|
|
|
80
|
|
|
public function setUp() |
81
|
|
|
{ |
82
|
|
|
$this->privateProperties = new ClassWithPrivateProperties(); |
83
|
|
|
$this->protectedProperties = new ClassWithProtectedProperties(); |
84
|
|
|
$this->publicProperties = new ClassWithPublicProperties(); |
85
|
|
|
$this->mixedProperties = new ClassWithMixedProperties(); |
86
|
|
|
|
87
|
|
|
$this->accessPrivateProperty = new ReflectionProperty(ClassWithPrivateProperties::class, 'property0'); |
88
|
|
|
$this->accessPrivateProperty->setAccessible(true); |
89
|
|
|
|
90
|
|
|
$this->accessProtectedProperty = new ReflectionProperty(ClassWithProtectedProperties::class, 'property0'); |
91
|
|
|
$this->accessProtectedProperty->setAccessible(true); |
92
|
|
|
|
93
|
|
|
$this->accessMixedPropertiesPrivate = new ReflectionProperty( |
94
|
|
|
ClassWithMixedProperties::class, |
95
|
|
|
'privateProperty0' |
96
|
|
|
); |
97
|
|
|
$this->accessMixedPropertiesPrivate->setAccessible(true); |
98
|
|
|
|
99
|
|
|
$this->accessMixedPropertiesProtected = new ReflectionProperty( |
100
|
|
|
ClassWithMixedProperties::class, |
101
|
|
|
'protectedProperty0' |
102
|
|
|
); |
103
|
|
|
$this->accessMixedPropertiesProtected->setAccessible(true); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function benchPrivatePropertyRead() : void |
107
|
|
|
{ |
108
|
|
|
$this->accessPrivateProperty->getValue($this->privateProperties); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function benchPrivatePropertyWrite() : void |
112
|
|
|
{ |
113
|
|
|
$this->accessPrivateProperty->setValue($this->privateProperties, 'foo'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function benchProtectedPropertyRead() : void |
117
|
|
|
{ |
118
|
|
|
$this->accessProtectedProperty->getValue($this->protectedProperties); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function benchProtectedPropertyWrite() : void |
122
|
|
|
{ |
123
|
|
|
$this->accessProtectedProperty->setValue($this->protectedProperties, 'foo'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function benchPublicPropertyRead() : void |
127
|
|
|
{ |
128
|
|
|
$this->publicProperties->property0; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function benchPublicPropertyWrite() : void |
132
|
|
|
{ |
133
|
|
|
$this->publicProperties->property0 = 'foo'; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function benchMixedPropertiesPrivatePropertyRead() : void |
137
|
|
|
{ |
138
|
|
|
$this->accessMixedPropertiesPrivate->getValue($this->mixedProperties); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function benchMixedPropertiesPrivatePropertyWrite() : void |
142
|
|
|
{ |
143
|
|
|
$this->accessMixedPropertiesPrivate->setValue($this->mixedProperties, 'foo'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function benchMixedPropertiesProtectedPropertyRead() : void |
147
|
|
|
{ |
148
|
|
|
$this->accessMixedPropertiesProtected->getValue($this->mixedProperties); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function benchMixedPropertiesProtectedPropertyWrite() : void |
152
|
|
|
{ |
153
|
|
|
$this->accessMixedPropertiesProtected->setValue($this->mixedProperties, 'foo'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function benchMixedPropertiesPublicPropertyRead() : void |
157
|
|
|
{ |
158
|
|
|
$this->mixedProperties->publicProperty0; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function benchMixedPropertiesPublicPropertyWrite() : void |
162
|
|
|
{ |
163
|
|
|
$this->mixedProperties->publicProperty0 = 'foo'; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|