MightyPork

Profiler PHP class

Apr 4th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php namespace MightyPork\Wrack;
  2.  
  3. /**
  4.  * Utility for profiling.
  5.  */
  6. class Profiler
  7. {
  8.  
  9.     /**
  10.      * Get current time
  11.      *
  12.      * @return float time with microsecond precision
  13.      */
  14.     public static function now()
  15.     {
  16.         list($usec, $sec) = explode(" ", microtime());
  17.         return ((float) $usec + (float) $sec);
  18.     }
  19.  
  20.  
  21.     /**
  22.      * Start profiling
  23.      *
  24.      * @return float current time (profiling token)
  25.      */
  26.     public static function start()
  27.     {
  28.         return self::now();
  29.     }
  30.  
  31.  
  32.     /**
  33.      * Measure time elapsed since start
  34.      *
  35.      * @param float $start time obtained with "start()"
  36.      * @return string time elapsed (s)
  37.      */
  38.     public static function end($start)
  39.     {
  40.         return sprintf('%0.3f', self::now() - $start);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment