Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DebugHelper
- {
- /**
- * @var int
- */
- static $lastTime = 0;
- /**
- * @var int
- */
- static $lastMemory = 0;
- /**
- * @param string $message
- * @param bool $printTime
- * @param bool $printMemory
- */
- public static function printInfo(string $message, bool $printTime = true, bool $printMemory = true)
- {
- $currentTime = microtime(true);
- $currentMemory = memory_get_usage();
- $executedTime = $currentTime - self::$lastTime;
- $diffMemory = $currentMemory - self::$lastMemory;
- $diffMemory = $diffMemory/1024 . 'KB';
- if (empty(self::$lastTime)) {
- $executedTime = date('Y-m-d H:i:s', $executedTime);
- }
- echo "{$message} executed time: {$executedTime}, occupied memory: {$diffMemory}\n";
- self::$lastTime = $currentTime;
- self::$lastMemory = $currentMemory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement