public function formatIterationsShortSummary(IterationCollection $iterations)
 {
     $stats = $iterations->getStats();
     $timeUnit = $this->timeUnit->resolveDestUnit($iterations->getSubject()->getOutputTimeUnit());
     $mode = $this->timeUnit->resolveMode($iterations->getSubject()->getOutputMode());
     return sprintf('[μ Mo]/r: %s %s μRSD/r: %s%%', $this->timeUnit->format($stats['mean'], $timeUnit, $mode, null, false), $this->timeUnit->format($stats['mode'], $timeUnit, $mode, null, false), number_format($stats['rstdev'], 2));
 }
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     if ($iterations->hasException()) {
         $this->output->write(sprintf("    %-30s<error>ERROR</error>", $iterations->getSubject()->getName()));
         $this->output->write(PHP_EOL);
         return;
     }
     $this->output->write(sprintf("\t%s", $this->formatIterationsFullSummary($iterations)));
     $this->output->write(PHP_EOL);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     $stats = $iterations->getStats();
     $timeUnit = $iterations->getSubject()->getOutputTimeUnit();
     if (null === $timeUnit || $this->timeUnit->isOverridden()) {
         $timeUnit = $this->timeUnit->getDestUnit();
     }
     $suffix = TimeUnit::getSuffix($timeUnit);
     $this->output->write(sprintf("\tμ/r: %s%s\tμSD/r %s%s\tμRSD/r: %s%%", number_format(TimeUnit::convert($stats['mean'], TimeUnit::MICROSECONDS, $timeUnit), 3), $suffix, number_format(TimeUnit::convert($stats['stdev'], TimeUnit::MICROSECONDS, $timeUnit), 3), $suffix, number_format($stats['rstdev'], 2)));
     $this->output->write(PHP_EOL);
 }
Exemple #4
0
 public function iterationsEnd(IterationCollection $iterations)
 {
     // do not show reject runs
     if ($iterations->getRejectCount() > 0) {
         return;
     }
     $dot = $iterations->hasException() ? '<error>E</error>' : '.';
     if ($this->isCi) {
         $this->output->write($dot);
         return;
     }
     $this->buffer .= $dot;
     $this->output->write(sprintf("\r%s ", $this->buffer));
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     if ($iterations->getRejectCount() > 0) {
         return;
     }
     $stats = $iterations->getStats();
     $subject = $iterations->getSubject();
     $timeUnit = $subject->getOutputTimeUnit();
     if (null === $timeUnit || $this->timeUnit->isOverridden()) {
         $timeUnit = $this->timeUnit->getDestUnit();
     }
     $suffix = TimeUnit::getSuffix($timeUnit);
     $this->output->writeln(sprintf("\t%-30s P%s\tμ/r: %s%s\tμSD/r %s%s\tμRSD/r: %s%%", $subject->getName(), $iterations->getParameterSet()->getIndex(), number_format(TimeUnit::convert($stats['mean'], TimeUnit::MICROSECONDS, $timeUnit), 3), $suffix, number_format(TimeUnit::convert($stats['stdev'], TimeUnit::MICROSECONDS, $timeUnit), 3), $suffix, number_format($stats['rstdev'], 2)));
 }
Exemple #6
0
 protected function renderCollectionStatus(IterationCollection $collection)
 {
     $this->output->write(PHP_EOL);
     $this->output->write("");
     // clear the line
     $this->output->write(PHP_EOL);
     $this->output->write(sprintf('<info>subject</info> %s<info> with </info>%s<info> iteration(s) of </info>%s<info> rev(s),</info>', sprintf('%s', $collection->getSubject()->getName()), count($collection), $collection->getRevolutions()));
     $this->output->write(PHP_EOL);
     $this->output->write(sprintf('<info>parameters</info> %s', json_encode($collection->getParameterSet()->getArrayCopy(), true)));
     $this->output->write(PHP_EOL);
     $this->output->write("[" . 4 . 'A');
     // put the cursor back to the line with the measurements
     $this->output->write("");
     // put the cursor back at col 0
 }
 /**
  * It should mark iterations as rejected if they deviate too far from the mean.
  */
 public function testReject()
 {
     $iterations = new IterationCollection($this->subject->reveal(), $this->parameterSet->reveal(), 50);
     $iterations->replace(array($iter1 = $this->createIteration(4, -50), $iter2 = $this->createIteration(8, 0), $iter3 = $this->createIteration(4, -50), $iter4 = $this->createIteration(16, 100)));
     $iterations->computeStats();
     $this->assertCount(3, $iterations->getRejects());
     $this->assertContains($iter1, $iterations->getRejects());
     $this->assertContains($iter3, $iterations->getRejects());
     $this->assertContains($iter4, $iterations->getRejects());
     $this->assertNotContains($iter2, $iterations->getRejects());
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     if ($iterations->getRejectCount() > 0) {
         return;
     }
     $subject = $iterations->getSubject();
     if ($iterations->hasException()) {
         $this->output->writeln(sprintf('    t%-30s <error>ERROR</error>', $subject->getName()));
         return;
     }
     $this->output->writeln(sprintf("    %-30s I%s P%s\t%s", $subject->getName(), $iterations->count(), $iterations->getParameterSet()->getIndex(), $this->formatIterationsFullSummary($iterations)));
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     if ($iterations->getRejectCount() > 0) {
         return;
     }
     $subject = $iterations->getSubject();
     if ($iterations->hasException()) {
         $this->output->writeln(sprintf("\t%-30s <error>ERROR</error>", $subject->getName()));
         return;
     }
     $stats = $iterations->getStats();
     $timeUnit = $subject->getOutputTimeUnit();
     $outputMode = $subject->getOutputMode();
     $this->output->writeln(sprintf("\t%-30s I%s P%s\tμ/r: %s\tμSD/r %s\tμRSD/r: %s%%", $subject->getName(), $iterations->count(), $iterations->getParameterSet()->getIndex(), $this->timeUnit->format($stats['mean'], $timeUnit, $outputMode), $this->timeUnit->format($stats['stdev'], $timeUnit, TimeUnit::MODE_TIME), number_format($stats['rstdev'], 2)));
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function iterationsEnd(IterationCollection $iterations)
 {
     if ($iterations->hasException()) {
         $this->output->write(sprintf("    %-30s<error>ERROR</error>", $iterations->getSubject()->getName()));
         $this->output->write(PHP_EOL);
         return;
     }
     $stats = $iterations->getStats();
     $timeUnit = $iterations->getSubject()->getOutputTimeUnit();
     $mode = $iterations->getSubject()->getOutputMode();
     $this->output->write(sprintf("\tμ/r: %s\tμSD/r %s\tμRSD/r: %s%%", $this->timeUnit->format($stats['mean'], $this->timeUnit->resolveDestUnit($timeUnit), $this->timeUnit->resolveMode($mode)), $this->timeUnit->format($stats['stdev'], $this->timeUnit->resolveDestUnit($timeUnit), TimeUnit::MODE_TIME), number_format($stats['rstdev'], 2)));
     $this->output->write(PHP_EOL);
 }
 /**
  * It should throw an exception if getStats is called when an exception has been set.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage Cannot retrieve stats when an exception
  */
 public function testGetStatsWithExceptionException()
 {
     $iterations = new IterationCollection($this->subject->reveal(), $this->parameterSet->reveal(), 1, 1, 0);
     $iterations[0]->setResult(new IterationResult(4, null));
     $iterations->computeStats();
     $iterations->setException(new \Exception('Test'));
     $iterations->getStats();
 }
Exemple #12
0
 private function drawIterations(IterationCollection $collection, $specials, $tag, $current = null)
 {
     $subject = $collection->getSubject();
     $timeUnit = $subject->getOutputTimeUnit();
     $outputMode = $subject->getOutputMode();
     $this->output->write("");
     // put cursor at column 0
     $this->output->write(sprintf('#%-2s', $subject->getIndex()));
     $padding = 1;
     $depth = 0;
     for ($index = 0; $index < $collection->count(); $index++) {
         $otherIteration = $collection->getIteration($index);
         $time = 0;
         if ($otherIteration->hasResult()) {
             $time = $otherIteration->getResult()->getTime() / $otherIteration->getRevolutions();
         }
         $displayTime = number_format($this->timeUnit->toDestUnit($time, $this->timeUnit->resolveDestUnit($timeUnit), $this->timeUnit->resolveMode($outputMode)), $this->timeUnit->getPrecision());
         if (strlen($displayTime) > $padding) {
             $padding = strlen($displayTime);
         }
         $output = sprintf('%' . ($padding + 2) . 's', $displayTime);
         if ($current === $index) {
             $output = sprintf('<bg=green>%s</>', $output);
         } elseif (isset($specials[$otherIteration->getIndex()])) {
             $output = sprintf('<%s>%s</%s>', $tag, $output, $tag);
         }
         $this->output->write($output);
         if ($index > 0 && ($index + 1) % self::NUMBER_COLS == 0) {
             $depth++;
             $this->output->write(PHP_EOL);
             $this->output->write('   ');
         }
     }
     $this->depth = $depth;
     $this->output->write(sprintf(' (%s)', $this->timeUnit->getDestSuffix($this->timeUnit->resolveDestUnit($timeUnit), $this->timeUnit->resolveMode($outputMode))));
     $this->output->write("");
     // clear rest of the line
 }
Exemple #13
0
 private function drawIterations(IterationCollection $collection, array $specials, $tag)
 {
     $this->output->write("");
     // put cursor at column 0
     $timeUnit = $collection->getSubject()->getOutputTimeUnit();
     $outputMode = $collection->getSubject()->getOutputMode();
     $lines = array();
     $line = sprintf('%-' . self::INDENT . 's', '#' . $collection->getSubject()->getIndex());
     for ($index = 0; $index < $collection->count(); $index++) {
         $iteration = $collection->getIteration($index);
         $displayTime = $this->formatIterationTime($iteration);
         if (isset($specials[$iteration->getIndex()])) {
             $displayTime = sprintf('<%s>%' . $this->colWidth . 's</%s>', $tag, $displayTime, $tag);
         }
         $line .= $displayTime;
         if ($index > 0 && ($index + 1) % self::NUMBER_COLS == 0) {
             $lines[] = $line;
             $line = str_repeat(' ', self::INDENT);
         }
     }
     $lines[] = $line;
     $this->currentLine = count($lines) - 1;
     $output = trim(implode(PHP_EOL, $lines));
     $output .= sprintf(' (%s)', $this->timeUnit->getDestSuffix($this->timeUnit->resolveDestUnit($timeUnit), $this->timeUnit->resolveMode($outputMode)));
     $this->output->write(sprintf("%s", $output));
     // clear rest of the line
 }
 private function drawIterations(IterationCollection $iterations)
 {
     $subject = $iterations->getSubject();
     $this->output->write("");
     // clear the whole line
     $this->output->write(PHP_EOL);
     $this->output->write("");
     // clear the whole line
     $this->output->write("");
     $sigma = 2;
     $bins = 16;
     if ($iterations->isComputed()) {
         $times = $iterations->getZValues();
         $stats = $iterations->getStats();
         $freqs = Statistics::histogram($times, $bins, -$sigma, $sigma);
     } else {
         $stats = array('stdev' => 0, 'mean' => 0, 'max' => 0);
         $freqs = array_fill(0, $bins + 1, null);
     }
     $this->output->write(sprintf('#%-2d (σ = %s ) -%sσ [', $subject->getIndex(), $this->timeUnit->format($stats['stdev']), $sigma));
     $this->drawBlocks($freqs, $stats);
     $this->output->write(sprintf('] +%sσ <comment>%s</comment>', $sigma, $iterations->isComputed() ? $this->formatIterationsShortSummary($iterations) : ''));
     $this->output->write(PHP_EOL);
 }