You are here

public function MarkdownBenchmark::build in Markdown 3.0.x

1 call to MarkdownBenchmark::build()
MarkdownBenchmark::render in src/MarkdownBenchmark.php
Renders the object as a string.

File

src/MarkdownBenchmark.php, line 135

Class

MarkdownBenchmark
Class MarkdownBenchmark.

Namespace

Drupal\markdown

Code

public function build() {
  $time = 'N/A';
  $unit = NULL;
  if (!$this
    ->isInvalid()) {
    $milliseconds = $this
      ->getMilliseconds(FALSE);
    $time = '0.00';
    $unit = array_slice(array_keys(static::$units), -1, 1)[0];
    foreach (static::$units as $unit => $interval) {
      if ($milliseconds >= $interval) {
        $time = str_replace('.00', '', rtrim(number_format($interval > 0 ? $milliseconds / $interval : $milliseconds, 2), 0));
        break;
      }
    }
  }
  return [
    '#theme' => 'markdown_benchmark',
    '#time' => $time,
    '#unit' => $unit,
  ];
}