PhpBench\Model\Variant::computeStats PHP Метод

computeStats() публичный Метод

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

Usage Example

Пример #1
0
 private function processVariant(Variant $variant, \DOMElement $variantEl, array $resultClasses)
 {
     $errorEls = $variantEl->query('.//error');
     if ($errorEls->length) {
         $errors = [];
         foreach ($errorEls as $errorEl) {
             $error = new Error($errorEl->nodeValue, $errorEl->getAttribute('exception-class'), $errorEl->getAttribute('code'), $errorEl->getAttribute('file'), $errorEl->getAttribute('line'), '');
             $errors[] = $error;
         }
         $variant->createErrorStack($errors);
         return;
     }
     foreach ($variantEl->query('./iteration') as $iterationEl) {
         $results = [];
         foreach ($iterationEl->attributes as $attributeEl) {
             $name = $attributeEl->name;
             if (false === strpos($name, '-')) {
                 throw new \RuntimeException(sprintf('Expected attribute name to have a result key prefix, got "%s".', $name));
             }
             $prefix = substr($name, 0, strpos($name, '-'));
             if (!isset($resultClasses[$prefix])) {
                 throw new \RuntimeException(sprintf('No result class was provided with key "%s" for attribute "%s"', $prefix, $name));
             }
             $suffix = substr($name, strpos($name, '-') + 1);
             $results[$prefix][str_replace('-', '_', $suffix)] = $attributeEl->value;
         }
         $iteration = $variant->createIteration();
         foreach ($results as $resultKey => $resultData) {
             $iteration->setResult(call_user_func_array([$resultClasses[$resultKey], 'fromArray'], [$resultData]));
         }
     }
     // TODO: Serialize statistics ..
     $variant->computeStats();
 }
All Usage Examples Of PhpBench\Model\Variant::computeStats