I want to measure how much memory my function is using. As I want to do 10 iterations I’m using for loop for this. The problem is that after first iteration memory usage is always the same. What should I do that memory is calculated as first iteration to calculate averages?
My code snippet:
for ($i = 0; $i < 10; $i++) {
$memoryStart = memory_get_usage();
$basketsWithFilter = $customer->getBasketsExceedTotal(total: 5);
$memoryEnd = memory_get_usage() - $memoryStart;
$memoryWithFilter[] = round($memoryEnd / 1024);
}
In the array results are the following
17, 2, 2, 2, 2, 2, 2, 2, 2, 2