A N*_*A N 6 memory testing powershell
我正在尝试做一些需要资源承受压力的测试.我能够找到使用PowerShell最大化CPU使用率的方法.
start-job -ScriptBlock{
$result = 1;
foreach ($number in 1..2147483647)
{
$result = $result * $number
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法可以使用PowerShell来最大化内存使用量?
试试这个:
$mem_stress = "a" * 200MB
Run Code Online (Sandbox Code Playgroud)
编辑:如果cou无法在一个块中分配所有内存,请尝试在阵列中分配多个块:
$mem_stress = @()
for ($i = 0; $i -lt ###; $i++) { $mem_stress += ("a" * 200MB) }
Run Code Online (Sandbox Code Playgroud)
GC似乎没有干扰这一点(在分配了1 GB RAM的VM中进行快速测试的结果):
PS C:\> $a = @()
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
The '*' operator failed: Exception of type 'System.OutOfMemoryException' was thrown..
At line:1 char:13
+ $a += ("a" * <<<< 200MB)
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : OperatorFailed
Run Code Online (Sandbox Code Playgroud)