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); } }
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()); } }