JBZoo\Utils\Timer::formatMS PHP Метод

formatMS() публичный статический Метод

Formats the elapsed time as a string.
public static formatMS ( float $time ) : string
$time float
Результат string
    public static function formatMS($time)
    {
        $time = round($time * 1000, 3);
        $dec = 3;
        if (!$time || $time >= 10 || $time >= 100) {
            $dec = 0;
        } elseif ($time < 10 && $time >= 0.1) {
            $dec = 1;
        } elseif ($time <= 0.01) {
            $dec = 3;
        }
        return number_format($time, $dec, '.', ' ') . ' ms';
    }

Usage Example

Пример #1
0
 /**
  * Runs an empty test to determine the benchmark overhead and run each test once
  */
 private function _warmup()
 {
     $warmup = new Test('warmup', function () {
     });
     $this->_overhead = $warmup->runTest($this->_count);
     // One call each method for init (warmup)
     /** @var Test $test */
     foreach ($this->_tests as $test) {
         $test->runTest(1);
     }
     $this->out('PHP Overhead: ' . 'time=' . Timer::formatMS($this->_overhead['time']) . '; ' . 'memory=' . FS::format($this->_overhead['memory'], 2) . ';' . PHP_EOL);
 }
All Usage Examples Of JBZoo\Utils\Timer::formatMS