Overview

Namespaces

  • Yep
    • Stopwatch

Classes

  • Yep\Stopwatch\Event
  • Yep\Stopwatch\Formatter
  • Yep\Stopwatch\Lap
  • Yep\Stopwatch\Manager
  • Yep\Stopwatch\Stopwatch

Exceptions

  • Yep\Stopwatch\StopwatchAlreadyExistsException
  • Yep\Stopwatch\StopwatchDoesntExistException
  • Yep\Stopwatch\StopwatchEventDoesntExistException
  • Yep\Stopwatch\StopwatchLapNotStartedException
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Yep\Stopwatch;
 3: 
 4: class Formatter {
 5:     /**
 6:      * Returns formated memory
 7:      *
 8:      * @param float $size Memory in bytes
 9:      * @return string
10:      */
11:     public static function formatMemory($size) {
12:         $unit = ['b', 'kb', 'mb', 'gb'];
13:         $i = 0;
14: 
15:         if ($size > 0) {
16:             $i = floor(log($size, 1024));
17:             $divisor = pow(1024, $i);
18:             $size = $size / $divisor;
19:         }
20: 
21:         return number_format($size, 3, '.', ' ') . ' ' . $unit[(int)$i];
22:     }
23: 
24:     /**
25:      * Returns formated time
26:      *
27:      * @param float $s Time in seconds
28:      * @return string
29:      */
30:     public static function formatTime($s) {
31:         if ($s >= 60) {
32:             $time = $s / 60;
33:             $unit = 'm';
34:         }
35:         elseif ($s >= 1) {
36:             $time = $s;
37:             $unit = 's';
38:         }
39:         elseif (($ms = $s * 1000) >= 1) {
40:             $time = $ms;
41:             $unit = 'ms';
42:         }
43:         else {
44:             $time = $ms * 1000;
45:             $unit = 'μs';
46:         }
47: 
48:         return number_format($time, 3, '.', ' ') . " $unit";
49:     }
50: }
51: 
API documentation generated by ApiGen