/** * @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)); }
/** * @param callable $test * @param array $options * @return array */ public static function one($test, $options) { $options = array_merge(array('name' => 'One test', 'count' => 1000, 'output' => true), $options); // Prepare $bench = new Benchmark(); $bench->setCount($options['count']); $bench->add('Test', $test); declare (ticks=1); // Run tests $wrapProfiler = new Profiler(); $wrapProfiler->start(false); if ($options['output']) { $bench->out(PHP_EOL . '<pre>--------------- Start one bench: ' . $options['name'] . ' ---------------'); $result = $bench->run(true); $bench->out('-------------------- Finish one bench: ' . $options['name'] . ' ---------</pre>' . PHP_EOL); } else { $result = $bench->run(false); } $wrapProfiler->stop(); $result['total'] = array('time' => $wrapProfiler->getTime(), 'time_one' => $wrapProfiler->getTime() / $options['count'], 'memory' => $wrapProfiler->getMemory(), 'formated' => $wrapProfiler->getTotalUsage()); return $result; }