JBZoo\Utils\Timer::format PHP Method

format() public static method

Formats the elapsed time as a string.
public static format ( float $time ) : string
$time float
return string
    public static function format($time)
    {
        $time = round($time * 1000);
        foreach (self::$_times as $unit => $value) {
            if ($time >= $value) {
                $time = floor($time / $value * 100.0) / 100.0;
                return $time . ' ' . $unit . ($time == 1 ? '' : 's');
            }
        }
        return $time . ' ms';
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * 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);
 }
All Usage Examples Of JBZoo\Utils\Timer::format