[ 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 PHPUnit_Framework_TestCase; 22 23 /** 24 * Base performance test logic 25 * 26 * @author Marco Pivetta <ocramius@gmail.com> 27 * @license MIT 28 * 29 * @group Performance 30 * @coversNothing 31 */ 32 abstract class BasePerformanceTest extends PHPUnit_Framework_TestCase 33 { 34 /** 35 * @var float time when last capture was started 36 */ 37 private $startTime = 0; 38 39 /** 40 * @var int bytes when last capture was started 41 */ 42 private $startMemory = 0; 43 44 /** 45 * {@inheritDoc} 46 */ 47 public static function setUpBeforeClass() 48 { 49 $header = "Performance test - " . get_called_class() . ":"; 50 51 echo "\n\n" . str_repeat('=', strlen($header)) . "\n" . $header . "\n\n"; 52 } 53 54 /** 55 * Start profiler snapshot 56 */ 57 protected function startCapturing() 58 { 59 $this->startMemory = memory_get_usage(); 60 $this->startTime = microtime(true); 61 } 62 63 /** 64 * Echo current profiler output 65 * 66 * @param string $messageTemplate 67 * 68 * @return array 69 */ 70 protected function endCapturing($messageTemplate) 71 { 72 $time = microtime(true) - $this->startTime; 73 $memory = memory_get_usage() - $this->startMemory; 74 75 if (gc_enable()) { 76 gc_collect_cycles(); 77 } 78 79 echo sprintf($messageTemplate, $time, $memory / 1024) . "\n"; 80 81 return array( 82 'time' => $time, 83 'memory' => $memory 84 ); 85 } 86 87 /** 88 * Display comparison between two profiles 89 * 90 * @param array $baseProfile 91 * @param array $proxyProfile 92 */ 93 protected function compareProfile(array $baseProfile, array $proxyProfile) 94 { 95 $baseMemory = max(1, $baseProfile['memory']); 96 $timeOverhead = (($proxyProfile['time'] / $baseProfile['time']) - 1) * 100; 97 $memoryOverhead = (($proxyProfile['memory'] / $baseMemory) - 1) * 100; 98 99 echo sprintf('Comparison time / memory: %.2f%% / %.2f%%', $timeOverhead, $memoryOverhead) . "\n\n"; 100 } 101 }
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 |