Skip to content

Commit d5896f4

Browse files
Merge pull request #73 from supervoidcoder/copilot/add-performance-tests-ci
Add performance tests to CI with native PowerShell support
2 parents ce9b3ee + cb8dac4 commit d5896f4

8 files changed

Lines changed: 158 additions & 18 deletions

File tree

.github/workflows/build.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,26 @@ jobs:
7171
exit 1
7272
}
7373
74-
# Run all test .bat files
74+
# Run all test .bat and .ps1 files
7575
$env:force_ansi = 1
76+
77+
# Run .bat files
7678
Get-ChildItem -Path tests -Recurse -Filter *.bat | ForEach-Object {
7779
Write-Host "Running test: $($_.FullName)"
7880
& $_.FullName
79-
81+
if ($LASTEXITCODE -ne 0) {
82+
Write-Error "Test failed: $($_.FullName)"
83+
exit 1
84+
}
85+
}
86+
87+
# Run .ps1 files
88+
Get-ChildItem -Path tests -Recurse -Filter *.ps1 | ForEach-Object {
89+
Write-Host "Running test: $($_.FullName)"
90+
& $_.FullName
91+
if ($LASTEXITCODE -ne 0) {
92+
Write-Error "Test failed: $($_.FullName)"
93+
exit 1
94+
}
8095
}
8196

tests/performance/perf_help.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Performance test for help command
2+
# Measures time taken to display help information
3+
4+
Write-Host "Testing help command performance..." -ForegroundColor Yellow
5+
6+
# Warm-up run
7+
& win-witr --help | Out-Null
8+
9+
# Measure performance
10+
$result = Measure-Command {
11+
& win-witr --help | Out-Null
12+
}
13+
14+
Write-Host "Performance: Help command took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan
15+
16+
# Verify it worked
17+
if ($LASTEXITCODE -ne 0) {
18+
Write-Error "Help command failed"
19+
exit 1
20+
}
21+
22+
exit 0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Performance test for process lookup - 100 iterations
2+
# Measures time taken for each execution to look up a process by name
3+
4+
Write-Host "Testing process lookup performance over 100 iterations..." -ForegroundColor Yellow
5+
6+
# Verify win-witr works before starting measurements
7+
& win-witr win-witr.exe | Out-Null
8+
if ($LASTEXITCODE -ne 0) {
9+
Write-Error "win-witr process lookup failed"
10+
exit 1
11+
}
12+
13+
# Run 100 iterations and measure each
14+
Write-Host "Running 100 iterations of win-witr win-witr.exe..." -ForegroundColor Cyan
15+
1..100 | ForEach-Object {
16+
Measure-Command {
17+
& win-witr win-witr.exe | Out-Null
18+
} | Select-Object TotalMilliseconds
19+
}
20+
21+
Write-Host "Performance test completed successfully!" -ForegroundColor Green
22+
exit 0
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Performance test for PID lookup
2+
# Measures time taken to look up a process by PID
3+
4+
Write-Host "Testing PID lookup performance..." -ForegroundColor Yellow
5+
6+
# Get current PowerShell PID
7+
$currentPid = $PID
8+
9+
# Warm-up run
10+
& win-witr $currentPid | Out-Null
11+
12+
# Measure performance - average of 5 runs
13+
$measurements = @()
14+
for ($i = 1; $i -le 5; $i++) {
15+
$result = Measure-Command {
16+
& win-witr $currentPid | Out-Null
17+
}
18+
$measurements += $result.TotalMilliseconds
19+
}
20+
21+
$average = ($measurements | Measure-Object -Average).Average
22+
$min = ($measurements | Measure-Object -Minimum).Minimum
23+
$max = ($measurements | Measure-Object -Maximum).Maximum
24+
25+
Write-Host "Performance: PID lookup took avg=$([Math]::Round($average, 2))ms, min=$([Math]::Round($min, 2))ms, max=$([Math]::Round($max, 2))ms" -ForegroundColor Cyan
26+
27+
# Verify it worked
28+
if ($LASTEXITCODE -ne 0) {
29+
Write-Error "PID lookup failed"
30+
exit 1
31+
}
32+
33+
exit 0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Performance test for process lookup
2+
# Measures time taken to look up the win-witr process itself
3+
4+
Write-Host "Testing process lookup performance..." -ForegroundColor Yellow
5+
6+
# Warm-up run
7+
& win-witr win-witr.exe | Out-Null
8+
9+
# Measure performance - average of 5 runs
10+
$measurements = @()
11+
for ($i = 1; $i -le 5; $i++) {
12+
$result = Measure-Command {
13+
& win-witr win-witr.exe | Out-Null
14+
}
15+
$measurements += $result.TotalMilliseconds
16+
}
17+
18+
$average = ($measurements | Measure-Object -Average).Average
19+
$min = ($measurements | Measure-Object -Minimum).Minimum
20+
$max = ($measurements | Measure-Object -Maximum).Maximum
21+
22+
Write-Host "Performance: Process lookup took avg=$([Math]::Round($average, 2))ms, min=$([Math]::Round($min, 2))ms, max=$([Math]::Round($max, 2))ms" -ForegroundColor Cyan
23+
24+
# Verify it worked
25+
if ($LASTEXITCODE -ne 0) {
26+
Write-Error "Process lookup failed"
27+
exit 1
28+
}
29+
30+
exit 0

tests/performance/perf_version.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Performance test for version command
2+
# Measures time taken to display version information
3+
4+
Write-Host "Testing version command performance..." -ForegroundColor Yellow
5+
6+
# Warm-up run
7+
& win-witr --version | Out-Null
8+
9+
# Measure performance
10+
$result = Measure-Command {
11+
& win-witr --version | Out-Null
12+
}
13+
14+
Write-Host "Performance: Version command took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan
15+
16+
# Verify it worked
17+
if ($LASTEXITCODE -ne 0) {
18+
Write-Error "Version command failed"
19+
exit 1
20+
}
21+
22+
exit 0

tests/performance/stess_nested_shells.bat

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/performance/stress_nested_shells.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@ param(
33
[int]$CurrentDepth = 0,
44
[string]$CurrentShell = "powershell"
55
)
6-
cd D:\a\win-witr\win-witr
7-
# Ensure win-witr.exe is in PATH or current directory
86

7+
# Find the script directory and navigate to repository root
8+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
9+
$repoRoot = Split-Path -Parent (Split-Path -Parent $scriptDir)
10+
Set-Location $repoRoot
11+
12+
# Verify win-witr.exe is accessible
13+
if (-not (Test-Path "win-witr.exe" -PathType Leaf) -and -not (Get-Command "win-witr" -ErrorAction SilentlyContinue)) {
14+
Write-Error "win-witr.exe not found in current directory or PATH"
15+
exit 1
16+
}
917

1018
if ($CurrentDepth -ge $MaxDepth) {
1119
# We've reached max depth - run the actual test
1220
Write-Host "Reached depth $CurrentDepth - Running stress test..." -ForegroundColor Green
1321

1422
# Run the measurement
15-
cd D:\a\win-witr\win-witr
16-
.\win-witr win-witr.exe
1723
$result = Measure-Command {
18-
19-
.\win-witr win-witr.exe
24+
& win-witr win-witr.exe | Out-Null
2025
}
2126

22-
Write-Host "Time taken at depth ${CurrentDepth}: $($result.TotalMilliseconds)ms" -ForegroundColor Cyan
27+
Write-Host "Performance: Nested shell lookup at depth $CurrentDepth took $($result.TotalMilliseconds)ms" -ForegroundColor Cyan
2328

2429
# Verify it actually worked
2530
if ($LASTEXITCODE -ne 0) {

0 commit comments

Comments
 (0)