/** * 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; }
/** * It should return stats. */ public function testStats() { $distribution = new Distribution([-50, 0, 50, 100]); $this->assertEquals(100, $distribution->getSum()); $this->assertEquals(25, $distribution->getMean()); $this->assertEquals(-50, $distribution->getMin()); $this->assertEquals(100, $distribution->getMax()); $this->assertEquals(56, round($distribution->getStdev())); $this->assertEquals(3125, $distribution->getVariance()); $this->assertEquals(25, round($distribution->getMode())); }