Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

LazyLoadingGhostPerformanceTest.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.49 KiB


 001  <?php
 002  /*
 003   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 004   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 005   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 006   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 007   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 008   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 009   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 010   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 011   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 012   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 013   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 014   *
 015   * This software consists of voluntary contributions made by many individuals
 016   * and is licensed under the MIT license.
 017   */
 018   
 019  namespace ProxyManagerTest\Functional;
 020   
 021  use ProxyManager\Generator\ClassGenerator;
 022  use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
 023  use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
 024  use ProxyManager\Proxy\GhostObjectInterface;
 025  use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
 026  use ReflectionClass;
 027   
 028  /**
 029   * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator} produced objects
 030   *
 031   * @author Marco Pivetta <ocramius@gmail.com>
 032   * @license MIT
 033   *
 034   * @group Performance
 035   * @coversNothing
 036   */
 037  class LazyLoadingGhostPerformanceTest extends BaseLazyLoadingPerformanceTest
 038  {
 039      /**
 040       * @outputBuffering
 041       * @dataProvider getTestedClasses
 042       *
 043       * @param string                $className
 044       * @param array                 $methods
 045       * @param array                 $properties
 046       * @param \ReflectionProperty[] $reflectionProperties
 047       *
 048       * @return void
 049       */
 050      public function testProxyInstantiationPerformance(
 051          $className,
 052          array $methods,
 053          array $properties,
 054          array $reflectionProperties
 055      ) {
 056          $proxyName    = $this->generateProxy($className);
 057          $iterations   = 20000;
 058          $instances    = array();
 059          /* @var $proxies \ProxyManager\Proxy\GhostObjectInterface[] */
 060          $proxies      = array();
 061          $realInstance = new $className();
 062          $initializer  = function (
 063              GhostObjectInterface $proxy,
 064              $method,
 065              $params,
 066              & $initializer
 067          ) use (
 068              $reflectionProperties,
 069              $realInstance
 070          ) {
 071              $initializer = null;
 072   
 073              foreach ($reflectionProperties as $reflectionProperty) {
 074                  $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($realInstance));
 075              }
 076   
 077              return true;
 078          };
 079   
 080          $this->startCapturing();
 081   
 082          for ($i = 0; $i < $iterations; $i += 1) {
 083              $instances[] = new $className();
 084          }
 085   
 086          $baseProfile = $this->endCapturing(
 087              'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb'
 088          );
 089          $this->startCapturing();
 090   
 091          for ($i = 0; $i < $iterations; $i += 1) {
 092              $proxies[] = new $proxyName($initializer);
 093          }
 094   
 095          $proxyProfile = $this->endCapturing(
 096              'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'
 097          );
 098          $this->compareProfile($baseProfile, $proxyProfile);
 099          $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  }
 161