mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
Merge branch 'support/3.1.0' into support/3.1
# Conflicts: # tests/php-unit-tests/unitary-tests/core/DBObjectTest.php
This commit is contained in:
@@ -941,4 +941,40 @@ class DBObjectTest extends ItopDataTestCase
|
||||
{
|
||||
return $this->aReloadCount[$sClass][$sKey] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user