Skip to content

Instantly share code, notes, and snippets.

@Bujhm
Created July 22, 2017 21:56
Show Gist options
  • Save Bujhm/020c50074d5600aaf76e52ec8bbadfa4 to your computer and use it in GitHub Desktop.
Save Bujhm/020c50074d5600aaf76e52ec8bbadfa4 to your computer and use it in GitHub Desktop.
[CheckMemoryConsumption проверка занимаемой памяти (basic implementation))
/**
* [CheckMemoryConsumption проверка занимаемой памяти приложением]
* @param string $state [состояние одно из возможных: initial,final,peak]
* @return string
*/
public static function CheckMemoryConsumption($state = 'initial')
{
$memorySizeConsumptionString = '';
switch ($state){
case "initial":
$memorySizeConsumptionString = "Initial: ".number_format(memory_get_usage(), 0, ',', ' ')." bytes \n";
/* prints
Initial: 361400 bytes
*/
break;
case "final":
$memorySizeConsumptionString = "Final: ".number_format(memory_get_usage(), 0, ',', ' ')." bytes \n";
/* prints
Final: 885912 bytes
*/
break;
case "peak":
$memorySizeConsumptionString = "Peak: ".number_format(memory_get_peak_usage(), 0, ',', ' ')." bytes \n";
/* prints
Peak: 13687072 bytes
*/
default:
break;
}
return $memorySizeConsumptionString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment