format() 공개 정적인 메소드

Nice formatting for computer sizes (Bytes).
public static format ( integer $bytes, integer $decimals = 2 ) : string
$bytes integer The number in bytes to format
$decimals integer The number of decimal points to include
리턴 string
예제 #1
0
파일: Test.php 프로젝트: jbzoo/profiler
 /**
  * @param int $count
  * @return array
  */
 public function runTest($count = 1)
 {
     gc_collect_cycles();
     // Forces collection of any existing garbage cycles
     $this->_profiler->start();
     for ($i = 0; $i < $count; $i++) {
         // Store the result so it appears in memory profiling
         $this->_executeTest();
     }
     $this->_profiler->stop();
     $time = $this->_profiler->getTime();
     $timeOne = $this->_profiler->getTime() / $count;
     $memory = $this->_profiler->getMemory();
     return array('time' => $time, 'time_one' => $timeOne, 'memory' => $memory, 'count' => $count, 'formated' => sprintf("Time: %s/%s; Memory: %s; Count: %s", Timer::formatMS($time), Timer::formatMS($timeOne), FS::format($memory), $count));
 }
예제 #2
0
 /**
  * Format the results, rounding numbers, showing difference percentages
  * and removing a flat time based on the benchmark overhead
  *
  * @param  array $results array($name => array('time' => 1.0))
  * @return array array(array('Test' => $name, 'Time' => '1000 ms', 'Perc' => '100 %'))
  */
 public function formatResults(array $results)
 {
     uasort($results['list'], function ($testOne, $testTwo) {
         if ($testOne['time'] === $testTwo['time']) {
             return 0;
         } else {
             return $testOne['time'] < $testTwo['time'] ? -1 : 1;
         }
     });
     $minTime = INF;
     $minMemory = INF;
     foreach ($results['list'] as $name => $result) {
         // time
         $time = $result['time'];
         //$time -= $this->_overhead['time']; // Substract base_time
         $results['list'][$name]['time'] = $time;
         $minTime = min($minTime, $time);
         // memory
         $memory = $results['list'][$name]['memory'];
         $memory -= $this->_overhead['memory'];
         $results['list'][$name]['memory'] = $memory;
         $minMemory = min($minMemory, $memory);
     }
     $output = array();
     $isOne = count($results['list']) === 1;
     foreach ($results['list'] as $name => $result) {
         if ($isOne) {
             $output[] = array(self::COL_NAME => $name, self::COL_TIME => $this->_timeFormat($result['time'], 0), self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count), self::COL_MEMORY => FS::format($result['memory'], 2));
         } else {
             $output[] = array(self::COL_NAME => $name, self::COL_TIME => $this->_timeFormat($result['time'], 0), self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count), self::COL_TIME_REL => Vars::relativePercent($minTime, $result['time']), self::COL_MEMORY => FS::format($result['memory'], 2), self::COL_MEMORY_REL => Vars::relativePercent($minMemory, $result['memory']));
         }
     }
     return $output;
 }
예제 #3
0
파일: Profiler.php 프로젝트: jbzoo/profiler
 /**
  * Returns the resources (time, memory) of the request as a string.
  *
  * @param bool $getPeakMemory
  * @param bool $isRealMemory
  * @return string
  */
 public static function resourceUsage($getPeakMemory = true, $isRealMemory = false)
 {
     if ($getPeakMemory) {
         $message = 'Time: %s, Peak memory: %s';
         $memory = memory_get_peak_usage($isRealMemory);
     } else {
         $message = 'Time: %s, Memory: %s';
         $memory = memory_get_usage($isRealMemory);
     }
     $memory = FS::format($memory, 2);
     $time = Timer::format(Timer::timeSinceStart());
     return sprintf($message, $time, $memory);
 }
예제 #4
0
 public function testFormat()
 {
     $size = FS::format(512, 0);
     is('512 B', $size);
     $size = FS::format(512, 2);
     is('512 B', $size);
     $size = FS::format(2048, 1);
     is('2.0 KB', $size);
     $size = FS::format(25151251, 2);
     is('23.99 MB', $size);
     $size = FS::format(19971597926, 2);
     is('18.60 GB', $size);
     $size = FS::format(2748779069440, 1);
     is('2.5 TB', $size);
     $size = FS::format(2814750000000000.0, 1);
     is('2.5 PB', $size);
 }