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

LazyLoadingValueHolderPerformanceTest.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.65 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\VirtualProxyInterface;
025  use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
026  use ReflectionClass;
027   
028  /**
029   * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator} produced objects
030   *
031   * @author Marco Pivetta <ocramius@gmail.com>
032   * @license MIT
033   *
034   * @group Performance
035   * @coversNothing
036   */
037  class LazyLoadingValueHolderPerformanceTest extends BaseLazyLoadingPerformanceTest
038  {
039      /**
040       * @outputBuffering
041       * @dataProvider getTestedClasses
042       *
043       * @param string $className
044       * @param array  $methods
045       * @param array  $properties
046       *
047       * @return void
048       */
049      public function testProxyInstantiationPerformance($className, array $methods, array $properties)
050      {
051          $proxyName   = $this->generateProxy($className);
052          $iterations  = 20000;
053          $instances   = array();
054          /* @var $proxies \ProxyManager\Proxy\VirtualProxyInterface[] */
055          $proxies     = array();
056          $initializer = function (
057              & $valueHolder,
058              VirtualProxyInterface $proxy,
059              $method,
060              $params,
061              & $initializer
062          ) use ($className) {
063              $initializer = null;
064              $valueHolder = new $className();
065   
066              return true;
067          };
068   
069          $this->startCapturing();
070   
071          for ($i = 0; $i < $iterations; $i += 1) {
072              $instances[] = new $className();
073          }
074   
075          $baseProfile = $this->endCapturing(
076              'Instantiation for ' . $iterations . ' objects of type ' . $className . ': %fms / %fKb'
077          );
078          $this->startCapturing();
079   
080          for ($i = 0; $i < $iterations; $i += 1) {
081              $proxies[] = new $proxyName($initializer);
082          }
083   
084          $proxyProfile = $this->endCapturing(
085              'Instantiation for ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb'
086          );
087          $this->compareProfile($baseProfile, $proxyProfile);
088          $this->startCapturing();
089   
090          foreach ($proxies as $proxy) {
091              $proxy->initializeProxy();
092          }
093   
094          $this->endCapturing('Initialization of ' . $iterations . ' proxies of type ' . $className . ': %fms / %fKb');
095   
096          foreach ($methods as $methodName => $parameters) {
097              $this->profileMethodAccess($className, $instances, $proxies, $methodName, $parameters);
098          }
099   
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  }
135