/** * Runs an empty test to determine the benchmark overhead and run each test once */ private function _warmup() { $warmup = new Test('warmup', function () { }); $this->_overhead = $warmup->runTest($this->_count); // One call each method for init (warmup) /** @var Test $test */ foreach ($this->_tests as $test) { $test->runTest(1); } $this->out('PHP Overhead: ' . 'time=' . Timer::formatMS($this->_overhead['time']) . '; ' . 'memory=' . FS::format($this->_overhead['memory'], 2) . ';' . PHP_EOL); }
/** * @param int $count * @return array */ public function runTest($count = 1) { gc_collect_cycles(); // Forces collection of any existing garbage cycles $this->_profiler->start(); for ($i = 0; $i < $count; $i++) { // Store the result so it appears in memory profiling $this->_executeTest(); } $this->_profiler->stop(); $time = $this->_profiler->getTime(); $timeOne = $this->_profiler->getTime() / $count; $memory = $this->_profiler->getMemory(); return array('time' => $time, 'time_one' => $timeOne, 'memory' => $memory, 'count' => $count, 'formated' => sprintf("Time: %s/%s; Memory: %s; Count: %s", Timer::formatMS($time), Timer::formatMS($timeOne), FS::format($memory), $count)); }
/** * Returns the resources (time, memory) of the request as a string. * * @param bool $getPeakMemory * @param bool $isRealMemory * @return string */ public static function resourceUsage($getPeakMemory = true, $isRealMemory = false) { if ($getPeakMemory) { $message = 'Time: %s, Peak memory: %s'; $memory = memory_get_peak_usage($isRealMemory); } else { $message = 'Time: %s, Memory: %s'; $memory = memory_get_usage($isRealMemory); } $memory = FS::format($memory, 2); $time = Timer::format(Timer::timeSinceStart()); return sprintf($message, $time, $memory); }
public function testTimeSinceStart() { isTrue(Timer::timeSinceStart()); }