[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/ -> LazyLoadingValueHolderPerformanceTest.php (source)

   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\VirtualProxyInterface;
  25  use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
  26  use ReflectionClass;
  27  
  28  /**
  29   * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator} produced objects
  30   *
  31   * @author Marco Pivetta <ocramius@gmail.com>
  32   * @license MIT
  33   *
  34   * @group Performance
  35   * @coversNothing
  36   */
  37  class LazyLoadingValueHolderPerformanceTest extends BaseLazyLoadingPerformanceTest
  38  {
  39      /**
  40       * @outputBuffering
  41       * @dataProvider getTestedClasses
  42       *
  43       * @param string $className
  44       * @param array  $methods
  45       * @param array  $properties
  46       *
  47       * @return void
  48       */
  49      public function testProxyInstantiationPerformance($className, array $methods, array $properties)
  50      {
  51          $proxyName   = $this->generateProxy($className);
  52          $iterations  = 20000;
  53          $instances   = array();
  54          /* @var $proxies \ProxyManager\Proxy\VirtualProxyInterface[] */
  55          $proxies     = array();
  56          $initializer = function (
  57              & $valueHolder,
  58              VirtualProxyInterface $proxy,
  59              $method,
  60              $params,
  61              & $initializer
  62          ) use ($className) {
  63              $initializer = null;
  64              $valueHolder = new $className();
  65  
  66              return true;
  67          };
  68  
  69          $this->startCapturing();
  70  
  71          for ($i = 0; $i < $iterations; $i += 1) {
  72              $instances[] = new $className();
  73          }
  74  
  75          $baseProfile = $this->endCapturing(
  76              'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb'
  77          );
  78          $this->startCapturing();
  79  
  80          for ($i = 0; $i < $iterations; $i += 1) {
  81              $proxies[] = new $proxyName($initializer);
  82          }
  83  
  84          $proxyProfile = $this->endCapturing(
  85              'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'
  86          );
  87          $this->compareProfile($baseProfile, $proxyProfile);
  88          $this->startCapturing();
  89  
  90          foreach ($proxies as $proxy) {
  91              $proxy->initializeProxy();
  92          }
  93  
  94          $this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb');
  95  
  96          foreach ($methods as $methodName => $parameters) {
  97              $this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters);
  98          }
  99  
 100          foreach ($properties as $property) {
 101              $this->profilePropertyWrites($className, $instances, $proxies, $property);
 102              $this->profilePropertyReads($className, $instances, $proxies, $property);
 103              $this->profilePropertyIsset($className, $instances, $proxies, $property);
 104              $this->profilePropertyUnset($className, $instances, $proxies, $property);
 105          }
 106      }
 107  
 108      /**
 109       * @return array
 110       */
 111      public function getTestedClasses()
 112      {
 113          return array(
 114              array('stdClass', array(), array()),
 115              array('ProxyManagerTestAsset\\BaseClass', array('publicMethod' => array()), array('publicProperty')),
 116          );
 117      }
 118  
 119      /**
 120       * {@inheritDoc}
 121       */
 122      protected function generateProxy($parentClassName)
 123      {
 124          $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
 125          $generator          = new LazyLoadingValueHolderGenerator();
 126          $generatedClass     = new ClassGenerator($generatedClassName);
 127          $strategy           = new EvaluatingGeneratorStrategy();
 128  
 129          $generator->generate(new ReflectionClass($parentClassName), $generatedClass);
 130          $strategy->generate($generatedClass);
 131  
 132          return $generatedClassName;
 133      }
 134  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1