Last active
August 29, 2015 14:14
-
-
Save AllenJB/32dbfb8c66a8cbc4ba10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bytes_to_human($bytes) { | |
$human = NULL; | |
if ($bytes < 1024) { | |
$human = number_format ($bytes, 0) .' bytes'; | |
} else if ($bytes < 1024*1024) { | |
$human = number_format (($bytes / 1024), 1) . ' KB'; | |
} else { | |
$human = number_format (($bytes / (1024*1024)), 1) . ' MB'; | |
} | |
return $human; | |
} | |
if (function_exists ('memory_get_usage')) { | |
$mem = memory_get_usage(); | |
$mem_text = bytes_to_human($mem); | |
$rmem = memory_get_usage(TRUE); | |
$rmem_text = bytes_to_human ($rmem); | |
echo "Memory Usage: ". $mem_text ." / Real: ". $rmem_text ." :: "; | |
unset ($mem, $mem_text, $rmem, $rmem_text); | |
} | |
if (function_exists('memory_get_peak_usage')) { | |
echo "Peak Mem Usage: "; | |
$mem = bytes_to_human(memory_get_peak_usage()); | |
$rmem = bytes_to_human(memory_get_peak_usage(TRUE)); | |
echo $mem ." / Real: ". $rmem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment