public function testStartAndStop() { $profiler = new Profiler(); $profiler->start(); sleep(1); $profiler->stop(); $this->assertStringMatchesFormat('Time: %s; Memory: %s', $profiler->getTotalUsage()); }
/** * @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; }