Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->resultsFactory = $this->getMock('Athletic\\Factories\\MethodResultsFactory', array(), array(), '', false);
     $this->resultsFactory->expects($this->any())->method('create')->will($this->returnCallback(function ($name, $result, $iterations) {
         return new MethodResults($name, $result, $iterations);
     }));
 }
Ejemplo n.º 2
0
 /**
  * @param string $method
  * @param int    $annotations
  *
  * @return MethodResults
  */
 private function runMethodBenchmark($method, $annotations)
 {
     $iterations = $annotations['iterations'];
     $avgCalibration = $this->getCalibrationTime($iterations);
     $results = array();
     for ($i = 0; $i < $iterations; ++$i) {
         $this->setUp();
         $results[$i] = $this->timeMethod($method) - $avgCalibration;
         $this->tearDown();
     }
     $finalResults = $this->methodResultsFactory->create($method, $results, $iterations);
     $this->setOptionalAnnotations($finalResults, $annotations);
     return $finalResults;
 }
Ejemplo n.º 3
0
 /**
  * @param string $method
  * @param Annotations $annotations
  *
  * @return MethodResults
  */
 private function runMethodBenchmark($method, $annotations)
 {
     $iterations = isset($annotations['iterations']) ? $annotations['iterations'] : PHP_INT_MAX;
     $maxRuntime = isset($annotations['maxRuntime']) ? $annotations['maxRuntime'] : PHP_INT_MAX;
     $avgCalibration = $this->getCalibrationTime(min($iterations, static::MAX_CALIBRATION_ITERATIONS));
     $start = microtime(true);
     $results = array();
     for ($i = 0; $i < $iterations; ++$i) {
         $this->setUp();
         $results[$i] = $this->timeMethod($method) - $avgCalibration;
         $this->tearDown();
         if (microtime(true) - $start >= $maxRuntime) {
             break;
         }
     }
     $finalResults = $this->methodResultsFactory->create($method, $results, count($results));
     $this->setOptionalAnnotations($finalResults, $annotations);
     return $finalResults;
 }