Ejemplo n.º 1
0
 /**
  * @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));
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 3
0
 public function testResourceUsage()
 {
     $this->assertStringMatchesFormat('Time: %s, Peak memory: %s', Profiler::resourceUsage());
     $this->assertStringMatchesFormat('Time: %s, Memory: %s', Profiler::resourceUsage(false));
 }