getIterations() public method

Override the number of iterations to execute.
public getIterations ( $default = null ) : integer
return integer
 /**
  * Defaults should be ignored if explicit values are set in the context.
  */
 public function testOverride()
 {
     $context = new RunnerContext(__DIR__, array('iterations' => 20, 'revolutions' => 30, 'retry_threshold' => 40));
     $this->assertEquals(20, $context->getIterations(10));
     $this->assertEquals(30, $context->getRevolutions(10));
     $this->assertEquals(40, $context->getRetryThreshold(10));
 }
Beispiel #2
0
 private function runIterations(ExecutorInterface $executor, RunnerContext $context, SubjectMetadata $subject, ParameterSet $parameterSet, \DOMElement $variantEl)
 {
     $iterationCount = $context->getIterations($subject->getIterations());
     $revolutionCount = $context->getRevolutions($subject->getRevs());
     $warmupCount = $context->getWarmup($subject->getWarmUp());
     $executorConfig = $this->executorRegistry->getConfig($context->getExecutor());
     $iterationCollection = new IterationCollection($subject, $parameterSet, $iterationCount, $revolutionCount, $warmupCount, $context->getRetryThreshold($this->retryThreshold));
     $this->logger->iterationsStart($iterationCollection);
     try {
         foreach ($iterationCollection as $iteration) {
             $this->runIteration($executor, $executorConfig, $iteration, $context->getSleep($subject->getSleep()));
         }
     } catch (\Exception $e) {
         $iterationCollection->setException($e);
         $this->logger->iterationsEnd($iterationCollection);
         $this->appendException($variantEl, $e);
         return;
     }
     $iterationCollection->computeStats();
     $this->logger->iterationsEnd($iterationCollection);
     while ($iterationCollection->getRejectCount() > 0) {
         $this->logger->retryStart($iterationCollection->getRejectCount());
         $this->logger->iterationsStart($iterationCollection);
         foreach ($iterationCollection->getRejects() as $reject) {
             $reject->incrementRejectionCount();
             $this->runIteration($executor, $executorConfig, $reject, $context->getSleep($subject->getSleep()));
         }
         $iterationCollection->computeStats();
         $this->logger->iterationsEnd($iterationCollection);
     }
     $stats = $iterationCollection->getStats();
     foreach ($iterationCollection as $iteration) {
         $iterationEl = $variantEl->ownerDocument->createElement('iteration');
         $iterationEl->setAttribute('net-time', $iteration->getResult()->getTime());
         $iterationEl->setAttribute('rev-time', $iteration->getResult()->getTime() / $iteration->getRevolutions());
         $iterationEl->setAttribute('z-value', $iteration->getZValue());
         $iterationEl->setAttribute('memory', $iteration->getResult()->getMemory());
         $iterationEl->setAttribute('deviation', $iteration->getDeviation());
         $iterationEl->setAttribute('rejection-count', $iteration->getRejectionCount());
         $variantEl->appendChild($iterationEl);
     }
     $statsEl = $variantEl->appendElement('stats');
     foreach ($stats as $statName => $statValue) {
         $statsEl->setAttribute($statName, $statValue);
     }
 }
Beispiel #3
0
 private function runBenchmark(ExecutorInterface $executor, RunnerContext $context, Benchmark $benchmark, BenchmarkMetadata $benchmarkMetadata)
 {
     if ($benchmarkMetadata->getBeforeClassMethods()) {
         $executor->executeMethods($benchmarkMetadata, $benchmarkMetadata->getBeforeClassMethods());
     }
     // the keys are subject names, convert them to numerical indexes.
     $subjectMetadatas = array_filter($benchmarkMetadata->getSubjects(), function ($subjectMetadata) {
         if ($subjectMetadata->getSkip()) {
             return false;
         }
         return true;
     });
     $subjectMetadatas = array_values($subjectMetadatas);
     foreach ($subjectMetadatas as $subjectMetadata) {
         // override parameters
         $subjectMetadata->setIterations($context->getIterations($subjectMetadata->getIterations()));
         $subjectMetadata->setRevs($context->getRevolutions($subjectMetadata->getRevs()));
         $subjectMetadata->setWarmup($context->getWarmup($subjectMetadata->getWarmUp()));
         $subjectMetadata->setSleep($context->getSleep($subjectMetadata->getSleep()));
         $subjectMetadata->setRetryThreshold($context->getRetryThreshold($this->retryThreshold));
         $benchmark->createSubjectFromMetadata($subjectMetadata);
     }
     $this->logger->benchmarkStart($benchmark);
     foreach ($benchmark->getSubjects() as $index => $subject) {
         $subjectMetadata = $subjectMetadatas[$index];
         $this->logger->subjectStart($subject);
         $this->runSubject($executor, $context, $subject, $subjectMetadata);
         $this->logger->subjectEnd($subject);
     }
     $this->logger->benchmarkEnd($benchmark);
     if ($benchmarkMetadata->getAfterClassMethods()) {
         $executor->executeMethods($benchmarkMetadata, $benchmarkMetadata->getAfterClassMethods());
     }
 }
Beispiel #4
0
 private function runIterations(RunnerContext $context, SubjectMetadata $subject, ParameterSet $parameterSet, \DOMElement $variantEl)
 {
     $iterationCount = $context->getIterations($subject->getIterations());
     $revolutionCount = $context->getRevolutions($subject->getRevs());
     $iterationCollection = new IterationCollection($subject, $parameterSet, $context->getRetryThreshold($this->retryThreshold));
     $this->logger->iterationsStart($iterationCollection);
     $iterations = $iterationCollection->spawnIterations($iterationCount, $revolutionCount);
     foreach ($iterations as $iteration) {
         $this->runIteration($iteration, $subject->getSleep());
         $iterationCollection->add($iteration);
     }
     $iterationCollection->computeStats();
     $this->logger->iterationsEnd($iterationCollection);
     while ($iterationCollection->getRejectCount() > 0) {
         $this->logger->retryStart($iterationCollection->getRejectCount());
         $this->logger->iterationsStart($iterationCollection);
         foreach ($iterationCollection->getRejects() as $reject) {
             $reject->incrementRejectionCount();
             $this->runIteration($reject, $context->getSleep($subject->getSleep()));
         }
         $iterationCollection->computeStats();
         $this->logger->iterationsEnd($iterationCollection);
     }
     $stats = $iterationCollection->getStats();
     foreach ($iterationCollection as $iteration) {
         $iterationEl = $variantEl->ownerDocument->createElement('iteration');
         $iterationEl->setAttribute('revs', $iteration->getRevolutions());
         $iterationEl->setAttribute('time-net', $iteration->getResult()->getTime());
         $iterationEl->setAttribute('time', $iteration->getResult()->getTime() / $iteration->getRevolutions());
         $iterationEl->setAttribute('z-value', $iteration->getZValue());
         $iterationEl->setAttribute('memory', $iteration->getResult()->getMemory());
         $iterationEl->setAttribute('deviation', $iteration->getDeviation());
         $iterationEl->setAttribute('rejection-count', $iteration->getRejectionCount());
         $variantEl->appendChild($iterationEl);
     }
     $statsEl = $variantEl->appendElement('stats');
     foreach ($stats as $statName => $statValue) {
         $statsEl->setAttribute($statName, $statValue);
     }
 }
 /**
  * Defaults should be ignored if explicit values are set in the context.
  */
 public function testOverride()
 {
     $context = new RunnerContext(__DIR__, ['iterations' => [20], 'revolutions' => [30], 'retry_threshold' => 40]);
     $this->assertEquals([20], $context->getIterations([10]));
     $this->assertEquals([30], $context->getRevolutions([10]));
     $this->assertEquals(40, $context->getRetryThreshold(10));
 }