N°6716 - High memory Consomption and performance issue

This commit is contained in:
Eric Espie
2023-09-13 15:58:26 +02:00
parent 5acf38ac36
commit 7fdbb59c30
7 changed files with 219 additions and 18 deletions

View File

@@ -897,4 +897,40 @@ class DBObjectTest extends ItopDataTestCase
return $oPerson;
}
/**
* @since 3.1.0-3 3.1.1 3.2.0 N°6716 test creation
*/
public function testConstructorMemoryFootprint():void
{
$idx = 0;
$fStart = microtime(true);
$fStartLoop = $fStart;
$iInitialPeak = 0;
$iMaxAllowedMemoryIncrease = 1 * 1024 * 1024;
for ($i = 0; $i < 5000; $i++) {
/** @noinspection PhpUnusedLocalVariableInspection We intentionally use a reference that will disappear on each loop */
$oPerson = new \Person();
if (0 == ($idx % 100)) {
$fDuration = microtime(true) - $fStartLoop;
$iMemoryPeakUsage = memory_get_peak_usage();
if ($iInitialPeak === 0) {
$iInitialPeak = $iMemoryPeakUsage;
$sInitialPeak = \utils::BytesToFriendlyFormat($iInitialPeak, 4);
}
$sCurrPeak = \utils::BytesToFriendlyFormat($iMemoryPeakUsage, 4);
echo "$idx ".sprintf('%.1f ms', $fDuration * 1000)." - Peak Memory Usage: $sCurrPeak\n";
$this->assertTrue(($iMemoryPeakUsage - $iInitialPeak) <= $iMaxAllowedMemoryIncrease , "Peak memory changed from $sInitialPeak to $sCurrPeak after $i loops");
$fStartLoop = microtime(true);
}
$idx++;
}
$fTotalDuration = microtime(true) - $fStart;
echo 'Total duration: '.sprintf('%.3f s', $fTotalDuration)."\n\n";
}
}