Lazily Provides summary statistics, also traversable.
Inheritance: implements IteratorAggregate
Example #1
0
 /**
  * It should return all the stats.
  */
 public function testReturnStats()
 {
     $distribution = new Distribution([10, 20]);
     $stats = $distribution->getStats();
     foreach (['min', 'max', 'sum', 'stdev', 'mean', 'mode', 'variance', 'rstdev'] as $key) {
         $this->assertArrayHasKey($key, $stats);
     }
     $this->assertEquals(10, $stats['min']);
     $this->assertEquals(20, $stats['max']);
 }
Example #2
0
 /**
  * Calculate and set the deviation from the mean time for each iteration. If
  * the deviation is greater than the rejection threshold, then mark the iteration as
  * rejected.
  */
 public function computeStats()
 {
     $this->rejects = [];
     $revs = $this->getRevolutions();
     if (0 === count($this->iterations)) {
         return;
     }
     $times = $this->getMetricValuesByRev(TimeResult::class, 'net');
     $retryThreshold = $this->getSubject()->getRetryThreshold();
     $this->stats = new Distribution($times, $this->computedStats);
     foreach ($this->iterations as $iteration) {
         // deviation is the percentage different of the value from the mean of the set.
         if ($this->stats->getMean() > 0) {
             $deviation = 100 / $this->stats->getMean() * ($iteration->getResult(TimeResult::class)->getRevTime($iteration->getVariant()->getRevolutions()) - $this->stats->getMean());
         } else {
             $deviation = 0;
         }
         // the Z-Value represents the number of standard deviations this
         // value is away from the mean.
         $revTime = $iteration->getResult(TimeResult::class)->getRevTime($revs);
         $zValue = $this->stats->getStdev() ? ($revTime - $this->stats->getMean()) / $this->stats->getStdev() : 0;
         if (null !== $retryThreshold) {
             if (abs($deviation) >= $retryThreshold) {
                 $this->rejects[] = $iteration;
             }
         }
         $iteration->setResult(new ComputedResult($zValue, $deviation));
     }
     $this->computed = true;
 }
Example #3
0
 private function drawIterations(Variant $variant)
 {
     $subject = $variant->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 ($variant->isComputed()) {
         $times = $variant->getMetricValues(ComputedResult::class, 'z_value');
         $stats = $variant->getStats();
         $freqs = Statistics::histogram($times, $bins, -$sigma, $sigma);
     } else {
         $stats = new Distribution([0]);
         $freqs = array_fill(0, $bins + 1, null);
     }
     $this->output->write(sprintf('#%-2d (σ = %s ) -%sσ [', $subject->getIndex(), $this->timeUnit->format($stats->getStdev()), $sigma));
     $this->drawBlocks($freqs, $stats);
     $this->output->write(sprintf('] +%sσ <comment>%s</comment>', $sigma, $variant->isComputed() ? $this->formatIterationsShortSummary($variant) : ''));
     $this->output->write(PHP_EOL);
 }