DebugKit\Shell\BenchmarkShell::_variance PHP Метод

_variance() защищенный Метод

Donald E. Knuth (1998). The Art of Computer Programming, volume 2: Seminumerical Algorithms, 3rd edn., p. 232. Boston: Addison-Wesley.
protected _variance ( array $times, boolean $sample = true ) : float
$times array Array of values
$sample boolean If true, calculates an unbiased estimate of the population variance from a finite sample.
Результат float Variance
    protected function _variance($times, $sample = true)
    {
        $n = $mean = $M2 = 0;
        foreach ($times as $time) {
            $n += 1;
            $delta = $time - $mean;
            $mean = $mean + $delta / $n;
            $M2 = $M2 + $delta * ($time - $mean);
        }
        if ($sample) {
            $n -= 1;
        }
        return $M2 / $n;
    }