Пример #1
0
 /**
  * @dataProvider  formatBytesProvider()
  * @depends       NumberTest::parseBytes()
  * @group         inflector
  */
 public function testFormatBytes($n, $si, $dp, $prefix, $symbol, $expected)
 {
     $this->assertSame($expected, String::formatBytes($n, $si, $dp, $prefix, $symbol));
 }
Пример #2
0
 /**
  * Outputs the information in the correct format.
  *
  * @param  bool  $verbose  Whether to output full information.
  *
  * @return  string  The benchmark data up to the current point.
  */
 protected static function output($verbose = false)
 {
     # Choose comment string based on render context.
     $ctx = RenderContext::get();
     switch ($ctx->getLanguage()) {
         case RenderContext::LANG_HTML:
         case RenderContext::LANG_XHTML:
             $prefix = '<!-- Benchmark:';
             $postfix = '-->';
             break;
         case RenderContext::LANG_JS:
         case RenderContext::LANG_CSS:
             $prefix = '/*** Benchmark:';
             $postfix = '***/';
             break;
         default:
             throw new BenchmarkException('Unsupported render context.');
     }
     # Retrieve required data.
     $a =& self::$data[0];
     $b =& self::$data[count(self::$data) - 1];
     # Calculate time differences.
     $real = $b['time']['real'] - $a['time']['real'];
     $user = $b['time']['user'] - $a['time']['user'];
     $system = $b['time']['system'] - $a['time']['system'];
     # Generate output.
     $output = $prefix;
     if ($verbose) {
         $output .= PHP_EOL . '     ';
         $output .= sprintf('Time:    %.5fs real, %.5fs user, %.5fs system', $real, $user, $system);
         if (isset($b['memory'])) {
             $output .= PHP_EOL . '     ';
             $output .= sprintf('Memory:  %s current, %s peak', String::formatBytes($b['memory']['current'], false, null, 2), String::formatBytes($b['memory']['peak'], false, null, 2));
         }
         $output .= PHP_EOL . '     ';
         $output .= sprintf('Queries: %d', $b['query']['count']);
         if (isset($b['cache'])) {
             $output .= PHP_EOL . '     ';
             $output .= sprintf('Cache:   %d hits, %d misses, %s used, %s available', $b['cache']['hits'], $b['cache']['misses'], String::formatBytes($b['cache']['memory_used'], false, null, 2), String::formatBytes($b['cache']['memory_limit'], false, null, 2));
         }
         $output .= ' ';
     } else {
         $output .= ' ';
         $output .= sprintf('Time: %.5fs', $real);
         $output .= '; ';
         $output .= sprintf('Memory: %s', String::formatBytes($b['memory']['peak'], false, null, 2));
         $output .= '; ';
         $output .= sprintf('Queries: %d', $b['query']['count']);
         $output .= ' ';
     }
     $output .= $postfix . PHP_EOL;
     if (self::$print) {
         echo $output;
     }
     return $output;
 }