[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 namespace ProxyManagerTest\Functional; 20 21 use ProxyManager\Generator\ClassGenerator; 22 use ProxyManager\Generator\Util\UniqueIdentifierGenerator; 23 use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; 24 use ProxyManager\Proxy\GhostObjectInterface; 25 use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator; 26 use ReflectionClass; 27 28 /** 29 * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator} produced objects 30 * 31 * @author Marco Pivetta <ocramius@gmail.com> 32 * @license MIT 33 * 34 * @group Performance 35 * @coversNothing 36 */ 37 class LazyLoadingGhostPerformanceTest extends BaseLazyLoadingPerformanceTest 38 { 39 /** 40 * @outputBuffering 41 * @dataProvider getTestedClasses 42 * 43 * @param string $className 44 * @param array $methods 45 * @param array $properties 46 * @param \ReflectionProperty[] $reflectionProperties 47 * 48 * @return void 49 */ 50 public function testProxyInstantiationPerformance( 51 $className, 52 array $methods, 53 array $properties, 54 array $reflectionProperties 55 ) { 56 $proxyName = $this->generateProxy($className); 57 $iterations = 20000; 58 $instances = array(); 59 /* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */ 60 $proxies = array(); 61 $realInstance = new $className(); 62 $initializer = function ( 63 GhostObjectInterface $proxy, 64 $method, 65 $params, 66 & $initializer 67 ) use ( 68 $reflectionProperties, 69 $realInstance 70 ) { 71 $initializer = null; 72 73 foreach ($reflectionProperties as $reflectionProperty) { 74 $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($realInstance)); 75 } 76 77 return true; 78 }; 79 80 $this->startCapturing(); 81 82 for ($i = 0; $i < $iterations; $i += 1) { 83 $instances[] = new $className(); 84 } 85 86 $baseProfile = $this->endCapturing( 87 'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb' 88 ); 89 $this->startCapturing(); 90 91 for ($i = 0; $i < $iterations; $i += 1) { 92 $proxies[] = new $proxyName($initializer); 93 } 94 95 $proxyProfile = $this->endCapturing( 96 'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb' 97 ); 98 $this->compareProfile($baseProfile, $proxyProfile); 99 $this->startCapturing(); 100 101 foreach ($proxies as $proxy) { 102 $proxy->initializeProxy(); 103 } 104 105 $this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'); 106 107 foreach ($methods as $methodName => $parameters) { 108 $this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters); 109 } 110 111 foreach ($properties as $property) { 112 $this->profilePropertyWrites($className, $instances, $proxies, $property); 113 $this->profilePropertyReads($className, $instances, $proxies, $property); 114 $this->profilePropertyIsset($className, $instances, $proxies, $property); 115 $this->profilePropertyUnset($className, $instances, $proxies, $property); 116 } 117 } 118 119 /** 120 * @return array 121 */ 122 public function getTestedClasses() 123 { 124 $testedClasses = array( 125 array('stdClass', array(), array()), 126 array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')), 127 ); 128 129 foreach ($testedClasses as $key => $testedClass) { 130 $reflectionProperties = array(); 131 $reflectionClass = new ReflectionClass($testedClass[0]); 132 133 foreach ($reflectionClass->getProperties() as $property) { 134 $property->setAccessible(true); 135 136 $reflectionProperties[$property->getName()] = $property; 137 } 138 139 $testedClasses[$key][] = $reflectionProperties; 140 } 141 142 return $testedClasses; 143 } 144 145 /** 146 * {@inheritDoc} 147 */ 148 protected function generateProxy($parentClassName) 149 { 150 $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); 151 $generator = new LazyLoadingGhostGenerator(); 152 $generatedClass = new ClassGenerator($generatedClassName); 153 $strategy = new EvaluatingGeneratorStrategy(); 154 155 $generator->generate(new ReflectionClass($parentClassName), $generatedClass); 156 $strategy->generate($generatedClass); 157 158 return $generatedClassName; 159 } 160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |