Skip to content

tommie0079/stress-test-windows-pc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

stress-test

quick note, takes time to stop the cpu and network test

function Start-StressMenu {
    # Set this window to High Priority
    (Get-Process -Id $PID).PriorityClass = 'High'
    
    Clear-Host
    Write-Host "--- Windows Hardware Stress Tool v2.9 ---" -ForegroundColor Cyan
    $active = Get-Job -State Running
    if ($active) { Write-Host "ACTIVE TEST: $($active[0].Name)" -ForegroundColor Yellow }
    else { Write-Host "ACTIVE TEST: NONE (IDLE)" -ForegroundColor Green }

    Write-Host "`n1. Stress CPU (All Cores)"
    Write-Host "2. Stress RAM (80% Auto-Detect)"
    Write-Host "3. Stress Hard Drive (High Intensity)"
    Write-Host "4. Stress Network (WiFi/Ethernet)"
    Write-Host "5. STOP ALL TESTS" -ForegroundColor Red
    Write-Host "6. Exit"
    
    $choice = Read-Host "`nSelect Option"

    if ($choice -match '^[1-4]$') { Stop-AllStress -Silent }

    switch ($choice) {
        1 { Start-CPUStress; Start-StressMenu }
        2 { Start-RAMStress; Start-StressMenu }
        3 { Start-DiskStress; Start-StressMenu }
        4 { Start-NetworkStress; Start-StressMenu }
        5 { Stop-AllStress; Start-StressMenu }
        6 { Stop-AllStress; exit }
        Default { Start-StressMenu }
    }
}

function Start-CPUStress {
    $cores = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors
    Write-Host "Launching $cores CPU stress threads..." -ForegroundColor Yellow
    for ($i = 0; $i -lt $cores; $i++) {
        Start-Job -Name "CPU_STRESS" -ScriptBlock { 
            while($true){ $result = [math]::Sqrt([math]::Log10([math]::Exp(1.5))) } 
        } | Out-Null
    }
}

function Start-RAMStress {
    $os = Get-CimInstance Win32_OperatingSystem
    $freeGB = [Math]::Round($os.FreePhysicalMemory / 1MB, 2)
    $targetGB = [Math]::Round($freeGB * 0.8, 2)

    Write-Host "Filling $targetGB GB of RAM..." -ForegroundColor Yellow
    Start-Job -Name "RAM_STRESS" -ScriptBlock {
        param($sizeGB)
        $storage = New-Object System.Collections.Generic.List[Byte[]]
        for ($i = 0; $i -lt ($sizeGB * 10); $i++) {
            $chunk = New-Object Byte[] 100MB
            for ($j = 0; $j -lt $chunk.Length; $j += 1MB) { $chunk[$j] = 1 }
            $storage.Add($chunk)
        }
        while($true) { Start-Sleep -Seconds 10 }
    } -ArgumentList $targetGB | Out-Null
}

function Start-DiskStress {
    Write-Host "Hammering Disk (4 Threads)..." -ForegroundColor Yellow
    for ($i = 1; $i -le 4; $i++) {
        Start-Job -Name "DISK_STRESS" -ScriptBlock {
            param($id)
            $path = "$env:TEMP\stress_$id.tmp"
            $data = New-Object Byte[] 200MB
            while($true) {
                $stream = New-Object System.IO.FileStream($path, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None, 4096, [System.IO.FileOptions]::WriteThrough)
                $stream.Write($data, 0, $data.Length)
                $stream.Close()
            }
        } -ArgumentList $i | Out-Null
    }
}

function Start-NetworkStress {
    Write-Host "Starting Network Stress..." -ForegroundColor Yellow
    # Using a fast download from Cloudflare
    $url = "https://speed.cloudflare.com/__down?bytes=1000000000"
    for ($i = 1; $i -le 4; $i++) {
        Start-Job -Name "NET_STRESS" -ScriptBlock {
            param($target)
            $client = New-Object System.Net.Http.HttpClient
            while($true) {
                try { $null = $client.GetByteArrayAsync($target).Result } catch { }
            }
        } -ArgumentList $url | Out-Null
    }
}

function Stop-AllStress {
    param([switch]$Silent)
    if (-not $Silent) { Write-Host "Cleaning up system..." -ForegroundColor Red }
    
    # Stop background jobs
    Get-Job | Stop-Job -ErrorAction SilentlyContinue
    Get-Job | Remove-Job -Force -ErrorAction SilentlyContinue
    
    # Kill background powershell processes WITHOUT showing errors if none are found
    $currentPid = $PID
    Get-Process "powershell" -ErrorAction SilentlyContinue | Where-Object { $_.Id -ne $currentPid } | Stop-Process -Force -ErrorAction SilentlyContinue

    # Cleanup memory and temp files
    [System.GC]::Collect()
    Get-ChildItem "$env:TEMP\stress_*.tmp" -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
    
    if (-not $Silent) { 
        Write-Host "IDLE - All tests stopped." -ForegroundColor Green
        Start-Sleep -Seconds 1 
    }
}

Start-StressMenu

About

stress-test-windows-pc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors