You are here

private function BenchmarkCommand::computePercentile in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Command/BenchmarkCommand.php \Drupal\webprofiler\Command\BenchmarkCommand::computePercentile()
  2. 8.2 webprofiler/src/Command/BenchmarkCommand.php \Drupal\webprofiler\Command\BenchmarkCommand::computePercentile()
  3. 4.x webprofiler/src/Command/BenchmarkCommand.php \Drupal\webprofiler\Command\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
Executes the current command.

File

webprofiler/src/Command/BenchmarkCommand.php, line 206

Class

BenchmarkCommand
Class BenchmarkCommand

Namespace

Drupal\webprofiler\Command

Code

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