Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class DebugHelper
  2. {
  3. /**
  4. * @var int
  5. */
  6. static $lastTime = 0;
  7.  
  8. /**
  9. * @var int
  10. */
  11. static $lastMemory = 0;
  12.  
  13. /**
  14. * @param string $message
  15. * @param bool $printTime
  16. * @param bool $printMemory
  17. */
  18. public static function printInfo(string $message, bool $printTime = true, bool $printMemory = true)
  19. {
  20. $currentTime = microtime(true);
  21. $currentMemory = memory_get_usage();
  22. $executedTime = $currentTime - self::$lastTime;
  23. $diffMemory = $currentMemory - self::$lastMemory;
  24. $diffMemory = $diffMemory/1024 . 'KB';
  25. if (empty(self::$lastTime)) {
  26. $executedTime = date('Y-m-d H:i:s', $executedTime);
  27. }
  28. echo "{$message} executed time: {$executedTime}, occupied memory: {$diffMemory}\n";
  29. self::$lastTime = $currentTime;
  30. self::$lastMemory = $currentMemory;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement