1 | <?php |
||
24 | final class LazyLoadingValueHolderInstantiationBench |
||
25 | { |
||
26 | private string $emptyClassProxy; |
||
|
|||
27 | private string $privatePropertiesProxy; |
||
28 | private string $protectedPropertiesProxy; |
||
29 | private string $publicPropertiesProxy; |
||
30 | private string $mixedPropertiesProxy; |
||
31 | |||
32 | public function setUp() : void |
||
33 | { |
||
34 | $this->emptyClassProxy = $this->generateProxy(EmptyClass::class); |
||
35 | $this->privatePropertiesProxy = $this->generateProxy(ClassWithPrivateProperties::class); |
||
36 | $this->protectedPropertiesProxy = $this->generateProxy(ClassWithProtectedProperties::class); |
||
37 | $this->publicPropertiesProxy = $this->generateProxy(ClassWithPublicProperties::class); |
||
38 | $this->mixedPropertiesProxy = $this->generateProxy(ClassWithMixedProperties::class); |
||
39 | } |
||
40 | |||
41 | public function benchOriginalConstructorInstantiationOfEmptyObject() : void |
||
42 | { |
||
43 | new $this->emptyClassProxy(); |
||
44 | } |
||
45 | |||
46 | public function benchInstantiationOfEmptyObject() : void |
||
47 | { |
||
48 | $this->emptyClassProxy::staticProxyConstructor(static function () : void { |
||
49 | }); |
||
50 | } |
||
51 | |||
52 | public function benchOriginalConstructorInstantiationOfObjectWithPrivateProperties() : void |
||
53 | { |
||
54 | new $this->privatePropertiesProxy(); |
||
55 | } |
||
56 | |||
57 | public function benchInstantiationOfObjectWithPrivateProperties() : void |
||
58 | { |
||
59 | $this->privatePropertiesProxy::staticProxyConstructor(static function () : void { |
||
60 | }); |
||
61 | } |
||
62 | |||
63 | public function benchOriginalConstructorInstantiationOfObjectWithProtectedProperties() : void |
||
64 | { |
||
65 | new $this->protectedPropertiesProxy(); |
||
66 | } |
||
67 | |||
68 | public function benchInstantiationOfObjectWithProtectedProperties() : void |
||
69 | { |
||
70 | $this->protectedPropertiesProxy::staticProxyConstructor(static function () : void { |
||
71 | }); |
||
72 | } |
||
73 | |||
74 | public function benchOriginalConstructorInstantiationOfObjectWithPublicProperties() : void |
||
75 | { |
||
76 | new $this->publicPropertiesProxy(); |
||
77 | } |
||
78 | |||
79 | public function benchInstantiationOfObjectWithPublicProperties() : void |
||
80 | { |
||
81 | $this->publicPropertiesProxy::staticProxyConstructor(static function () : void { |
||
82 | }); |
||
83 | } |
||
84 | |||
85 | public function benchOriginalConstructorInstantiationOfObjectWithMixedProperties() : void |
||
86 | { |
||
87 | new $this->mixedPropertiesProxy(); |
||
88 | } |
||
89 | |||
90 | public function benchInstantiationOfObjectWithMixedProperties() : void |
||
91 | { |
||
92 | $this->mixedPropertiesProxy::staticProxyConstructor(static function () : void { |
||
93 | }); |
||
94 | } |
||
95 | |||
96 | private function generateProxy(string $originalClass) : string |
||
97 | { |
||
98 | $generatedClassName = self::class . '\\' . $originalClass; |
||
99 | |||
100 | if (class_exists($generatedClassName)) { |
||
101 | return $generatedClassName; |
||
102 | } |
||
103 | |||
104 | $generatedClass = new ClassGenerator($generatedClassName); |
||
105 | |||
106 | (new LazyLoadingValueHolderGenerator())->generate(new ReflectionClass($originalClass), $generatedClass); |
||
107 | (new EvaluatingGeneratorStrategy())->generate($generatedClass); |
||
108 | |||
109 | return $generatedClassName; |
||
110 | } |
||
111 | } |
||
112 |