Skip to content

Instantly share code, notes, and snippets.

@AllenJB
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllenJB/32dbfb8c66a8cbc4ba10 to your computer and use it in GitHub Desktop.
Save AllenJB/32dbfb8c66a8cbc4ba10 to your computer and use it in GitHub Desktop.
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