Last active
December 18, 2015 08:09
-
-
Save shyamsalimkumar/5752485 to your computer and use it in GitHub Desktop.
PHP - Get info about your memory usage
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
echo "Initial: ".memory_get_usage()." bytes \n"; | |
/* prints | |
Initial: 361400 bytes | |
*/ | |
// let's use up some memory | |
for ($i = 0; $i < 100000; $i++) { | |
$array []= md5($i); | |
} | |
// let's remove half of the array | |
for ($i = 0; $i < 100000; $i++) { | |
unset($array[$i]); | |
} | |
echo "Final: ".memory_get_usage()." bytes \n"; | |
/* prints | |
Final: 885912 bytes | |
*/ | |
echo "Peak: ".memory_get_peak_usage()." bytes \n"; | |
/* prints | |
Peak: 13687072 bytes | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment