Is it possible to get the peak memory usage of a particular block of code in PHP? The memory_get_peak_usage()
function seems to get the peak over the entire process execution up to the point of the function call, but this is not what I'm trying to obtain, since other code blocks could have skewed the value. I'm trying to isolate code blocks themselves, rather than the process as a whole.
Example:
// Block 1
for ($i = 0; $i < $iterations; ++$i) {
// some code
}
// Block 2
for ($i = 0; $i < $iterations; ++$i) {
// some different code
}
// Determine which of the two blocks used the most memory during their execution here
Unfortunately, xdebug is not an option for me at this time.