function BenchmarkCommand::computePercentile
Computes percentile using The Nearest Rank method.
Parameters
\Drupal\webprofiler\Command\BenchmarkData[] $datas:
$percentile:
Return value
\Drupal\webprofiler\Command\BenchmarkData
Throws
\Exception
1 call to BenchmarkCommand::computePercentile()
- BenchmarkCommand::execute in webprofiler/
src/ Command/ BenchmarkCommand.php
File
-
webprofiler/
src/ Command/ BenchmarkCommand.php, line 206
Class
- BenchmarkCommand
- Class BenchmarkCommand
Namespace
Drupal\webprofiler\CommandCode
private function computePercentile($datas, $percentile) {
if ($percentile < 0 || $percentile > 100) {
throw new \Exception('Percentile has to be between 0 and 100');
}
$profiles = count($datas);
$n = ceil($percentile / 100 * $profiles);
$index = (int) $n - 1;
$orderedTime = $datas;
$this->getOrderedDatas($orderedTime, 'Time');
$orderedMemory = $datas;
$this->getOrderedDatas($orderedMemory, 'Memory');
return new BenchmarkData(NULL, $orderedMemory[$index]->getMemory(), $orderedTime[$index]->getTime());
}