Exemplo n.º 1
0
 /**
  * @covers ::getBackgroundColorNames
  */
 public function test_getBackgroundColorNames()
 {
     // When
     $expColors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'light_gray'];
     // Then
     $this->assertSame($expColors, Colors::getBackgroundColorNames());
 }
Exemplo n.º 2
0
 /**
  * Parse benchmark summary and return it string.
  *
  * @return string[]
  */
 public function summaryToStr()
 {
     $longestName = max(array_map('strlen', array_keys($this->summary)));
     $msg = [Colors::getColoredString($this->benchmarkName, 'green')];
     $format = 'Benchmark %s: execution: %s %% (%s sec), memory: %s %% (%s B), speed: %s /sec';
     foreach ($this->summary as $name => $summary) {
         $executionActual = number_format($summary['time'], 6);
         $executionPerc = number_format($summary['to_fastest'] * 100, 2);
         $memoryActual = $summary['memory'];
         $memoryPerc = number_format($summary['to_least_memory'] * 100, 2);
         $name = str_pad($name, $longestName, ' ', STR_PAD_LEFT);
         $name = Colors::getColoredString($name, 'blue');
         $per_sec = $summary['per_sec'] === 'unknown' ? 'unknown' : number_format($summary['per_sec'], 0, '.', ' ');
         $msg[] = sprintf($format, $name, $executionPerc, $executionActual, $memoryPerc, $memoryActual, $per_sec);
     }
     $msg[] = "\n";
     return $msg;
 }