public function render(Suite $suite, OutputInterface $output, $options = []) { $options = array_merge(['filter_benchmark' => true, 'show_args' => false, 'filter' => null], $options); foreach ($suite->getIterations() as $iteration) { $this->renderIteration($iteration, $output, $options); } }
public static function createSuite(array $options = [], $suiteIndex = null) { $options = array_merge(['uuid' => $suiteIndex, 'date' => '2016-02-06', 'revs' => 5, 'warmup' => 10, 'sleep' => 1, 'basetime' => 10, 'groups' => [], 'name' => 'test', 'benchmarks' => ['TestBench'], 'groups' => ['one', 'two', 'three'], 'parameters' => ['param1' => 'value1'], 'subjects' => ['benchOne'], 'env' => [], 'output_time_unit' => 'microseconds', 'output_time_precision' => 7, 'output_mode' => 'time', 'iterations' => [0, 10]], $options); $dateTime = new \DateTime($options['date']); $suite = new Suite($options['name'], $dateTime, null, [], [], $options['uuid']); foreach ($options['benchmarks'] as $benchmarkClass) { $benchmark = $suite->createBenchmark($benchmarkClass); $baseTime = $options['basetime']; foreach ($options['subjects'] as $subjectName) { $subject = $benchmark->createSubject($subjectName); $subject->setSleep($options['sleep']); $subject->setGroups($options['groups']); $subject->setOutputTimeUnit($options['output_time_unit']); $subject->setOutputTimePrecision($options['output_time_precision']); $subject->setOutputMode($options['output_mode']); $variant = $subject->createVariant(new ParameterSet(0, $options['parameters']), $options['revs'], $options['warmup']); $time = $baseTime; foreach ($options['iterations'] as $time) { $variant->createIteration(self::createResults($baseTime + $time, 200, 0)); } $variant->computeStats(); $baseTime++; } } $informations = []; foreach ($options['env'] as $name => $information) { $informations[] = new Information($name, $information); } $suite->setEnvInformations($informations); return $suite; }
private function processSuite(\DOMElement $suiteEl) { $suite = new Suite($suiteEl->getAttribute('context'), new \DateTime($suiteEl->getAttribute('date')), $suiteEl->getAttribute('config-path'), [], [], $suiteEl->getAttribute('uuid')); $informations = []; foreach ($suiteEl->query('./env/*') as $envEl) { $name = $envEl->nodeName; $info = []; foreach ($envEl->attributes as $iName => $valueAttr) { $info[$iName] = $valueAttr->nodeValue; } $informations[$name] = new Information($name, $info); } $resultClasses = []; foreach ($suiteEl->query('//result') as $resultEl) { $class = $resultEl->getAttribute('class'); if (!class_exists($class)) { throw new \RuntimeException(sprintf('XML file defines a non-existing result class "%s" - maybe you are missing an extension?', $class)); } $resultClasses[$resultEl->getAttribute('key')] = $class; } $suite->setEnvInformations($informations); foreach ($suiteEl->query('./benchmark') as $benchmarkEl) { $benchmark = $suite->createBenchmark($benchmarkEl->getAttribute('class')); $this->processBenchmark($benchmark, $benchmarkEl, $resultClasses); } return $suite; }
public function endSuite(Suite $suite) { $summary = $suite->getSummary(); $errorStacks = $suite->getErrorStacks(); if ($errorStacks) { $this->output->write(PHP_EOL); $this->output->writeln(sprintf('%d subjects encountered errors:', count($errorStacks))); $this->output->write(PHP_EOL); foreach ($errorStacks as $errorStack) { $this->output->writeln(sprintf('<error>%s::%s</error>', $errorStack->getVariant()->getSubject()->getBenchmark()->getClass(), $errorStack->getVariant()->getSubject()->getName())); $this->output->write(PHP_EOL); foreach ($errorStack as $error) { $this->output->writeln(sprintf(" %s %s\n\n <comment>%s</comment>\n", $error->getClass(), str_replace("\n", "\n ", $error->getMessage()), str_replace("\n", "\n ", $error->getTrace()))); } } } $this->output->writeln(sprintf('%s subjects, %s iterations, %s revs, %s rejects', number_format($summary->getNbSubjects()), number_format($summary->getNbIterations()), number_format($summary->getNbRevolutions()), number_format($summary->getNbRejects()))); $this->output->writeln(sprintf('(best [mean mode] worst) = %s [%s %s] %s (%s)', number_format($this->timeUnit->toDestUnit($summary->getMinTime()), 3), number_format($this->timeUnit->toDestUnit($summary->getMeanTime()), 3), number_format($this->timeUnit->toDestUnit($summary->getModeTime()), 3), number_format($this->timeUnit->toDestUnit($summary->getMaxTime()), 3), $this->timeUnit->getDestSuffix())); $this->output->writeln(sprintf('⅀T: %s μSD/r %s μRSD/r: %s%%', $this->timeUnit->format($summary->getTotalTime(), null, TimeUnit::MODE_TIME), $this->timeUnit->format($summary->getMeanStDev(), null, TimeUnit::MODE_TIME), number_format($summary->getMeanRelStDev(), 3))); }
/** * @param Suite $suite */ public function __construct(Suite $suite) { foreach ($suite->getBenchmarks() as $benchmark) { foreach ($benchmark->getSubjects() as $subject) { $this->nbSubjects++; foreach ($subject->getVariants() as $variant) { $this->nbIterations += count($variant); $this->nbRevolutions += $variant->getRevolutions(); $this->nbRejects += $variant->getRejectCount(); if ($variant->hasErrorStack()) { $this->errorStacks[] = $variant->getErrorStack(); continue; } foreach ($variant->getStats() as $name => $value) { $this->stats[$name][] = $value; } } } } }
/** * Run all benchmarks (or all applicable benchmarks) in the given path. * * The $name argument will set the "name" attribute on the "suite" element. * * @param string $contextName * @param string $path */ public function run(RunnerContext $context) { $executorConfig = $this->executorRegistry->getConfig($context->getExecutor()); $executor = $this->executorRegistry->getService($executorConfig['executor']); // build the collection of benchmarks to be executed. $benchmarkMetadatas = $this->benchmarkFinder->findBenchmarks($context->getPath(), $context->getFilters(), $context->getGroups()); $suite = new Suite($context->getContextName(), new \DateTime(), $this->configPath); $suite->setEnvInformations((array) $this->envSupplier->getInformations()); // log the start of the suite run. $this->logger->startSuite($suite); try { /* @var BenchmarkMetadata */ foreach ($benchmarkMetadatas as $benchmarkMetadata) { $benchmark = $suite->createBenchmark($benchmarkMetadata->getClass()); $this->runBenchmark($executor, $context, $benchmark, $benchmarkMetadata); } } catch (StopOnErrorException $e) { } $suite->generateUuid(); $this->logger->endSuite($suite); return $suite; }
private function getSuite(\ArrayObject $context, array $row) { $key = $row['run.uuid']; if (isset($context[self::SUITES][$key])) { return $context[self::SUITES][$key]; } $suite = new Suite($row['run.context'], new \DateTime($row['run.date']), null, [], [], $row['run.uuid']); $context[self::SUITES][$key] = $suite; $envRows = $this->repository->getRunEnvInformationRows($row['run.id']); $providerData = []; foreach ($envRows as $row) { if (!isset($providerData[$row['provider']])) { $providerData[$row['provider']] = []; } $providerData[$row['provider']][$row['ekey']] = $row['value']; } $informations = []; foreach ($providerData as $name => $data) { $informations[] = new Information($name, $data); } $suite->setEnvInformations($informations); return $suite; }
private function assertNoErrors(Suite $suite) { if ($errorStacks = $suite->getErrorStacks()) { $errorStack = reset($errorStacks); $this->fail('Runner encountered error: ' . $errorStack->getTop()->getMessage()); } if ($errorStacks = $suite->getErrorStacks()) { $errorStack = reset($errorStacks); $this->fail('Runner encountered error: ' . $errorStack->getTop()->getMessage()); } }