/
LazyLoadingValueHolderInstantiationBench.php
132 lines (108 loc) Β· 3.76 KB
/
LazyLoadingValueHolderInstantiationBench.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
declare(strict_types=1);
namespace ProxyManagerBench;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
use ProxyManager\Generator\ClassGenerator;
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
use ProxyManagerTestAsset\ClassWithMixedProperties;
use ProxyManagerTestAsset\ClassWithPrivateProperties;
use ProxyManagerTestAsset\ClassWithProtectedProperties;
use ProxyManagerTestAsset\ClassWithPublicProperties;
use ProxyManagerTestAsset\EmptyClass;
use ReflectionClass;
/**
* Benchmark that provides results for simple object instantiation for lazy loading value holder proxies
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*
* @BeforeMethods({"setUp"})
*/
class LazyLoadingValueHolderInstantiationBench
{
/**
* @var string
*/
private $emptyClassProxy;
/**
* @var string
*/
private $privatePropertiesProxy;
/**
* @var string
*/
private $protectedPropertiesProxy;
/**
* @var string
*/
private $publicPropertiesProxy;
/**
* @var string
*/
private $mixedPropertiesProxy;
public function setUp()
{
$this->emptyClassProxy = $this->generateProxy(EmptyClass::class);
$this->privatePropertiesProxy = $this->generateProxy(ClassWithPrivateProperties::class);
$this->protectedPropertiesProxy = $this->generateProxy(ClassWithProtectedProperties::class);
$this->publicPropertiesProxy = $this->generateProxy(ClassWithPublicProperties::class);
$this->mixedPropertiesProxy = $this->generateProxy(ClassWithMixedProperties::class);
}
public function benchOriginalConstructorInstantiationOfEmptyObject() : void
{
new $this->emptyClassProxy;
}
public function benchInstantiationOfEmptyObject() : void
{
($this->emptyClassProxy)::staticProxyConstructor(function () {
});
}
public function benchOriginalConstructorInstantiationOfObjectWithPrivateProperties() : void
{
new $this->privatePropertiesProxy;
}
public function benchInstantiationOfObjectWithPrivateProperties() : void
{
($this->privatePropertiesProxy)::staticProxyConstructor(function () {
});
}
public function benchOriginalConstructorInstantiationOfObjectWithProtectedProperties() : void
{
new $this->protectedPropertiesProxy;
}
public function benchInstantiationOfObjectWithProtectedProperties() : void
{
($this->protectedPropertiesProxy)::staticProxyConstructor(function () {
});
}
public function benchOriginalConstructorInstantiationOfObjectWithPublicProperties() : void
{
new $this->publicPropertiesProxy;
}
public function benchInstantiationOfObjectWithPublicProperties() : void
{
($this->publicPropertiesProxy)::staticProxyConstructor(function () {
});
}
public function benchOriginalConstructorInstantiationOfObjectWithMixedProperties() : void
{
new $this->mixedPropertiesProxy;
}
public function benchInstantiationOfObjectWithMixedProperties() : void
{
($this->mixedPropertiesProxy)::staticProxyConstructor(function () {
});
}
private function generateProxy(string $originalClass) : string
{
$generatedClassName = __CLASS__ . '\\' . $originalClass;
if (class_exists($generatedClassName)) {
return $generatedClassName;
}
$generatedClass = new ClassGenerator($generatedClassName);
(new LazyLoadingValueHolderGenerator())->generate(new ReflectionClass($originalClass), $generatedClass);
(new EvaluatingGeneratorStrategy())->generate($generatedClass);
return $generatedClassName;
}
}