-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmicro-adjust-benchmark.ps1
More file actions
72 lines (54 loc) · 2.32 KB
/
micro-adjust-benchmark.ps1
File metadata and controls
72 lines (54 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
param(
[double]$increment = 0.002,
[double]$start = 0.5,
[double]$end = 0.8,
[int]$samples = 20
)
function Is-Admin() {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function main() {
if (-not (Is-Admin)) {
Write-Host "error: administrator privileges required"
return 1
}
$iterations = ($end - $start) / $increment
$totalMs = $iterations * 102 * $samples
Write-Host "Approximate worst-case estimated time for completion: $([math]::Round($totalMs / 6E4, 2))mins"
Write-Host "Worst-case is determined by assuming Sleep(1) = ~2ms with 1ms Timer Resolution"
Write-Host "Start: $($start)ms, End: $($end)ms, Increment: $($increment)ms, Samples: $($samples)"
Stop-Process -Name "SetTimerResolution" -ErrorAction SilentlyContinue
Set-Location $PSScriptRoot
foreach ($dependency in @("SetTimerResolution.exe", "MeasureSleep.exe")) {
if (-not (Test-Path $dependency)) {
Write-Host "error: $($dependency) not exists in current directory"
return 1
}
}
"RequestedResolutionMs,DeltaMs,STDEV" | Out-File results.txt
for ($i = $start; $i -le $end; $i += $increment) {
Write-Host "info: benchmarking $($i)ms"
Start-Process ".\SetTimerResolution.exe" -ArgumentList @("--resolution", ($i * 1E4), "--no-console")
# unexpected results if there isn't a small delay after setting the resolution
Start-Sleep 1
$output = .\MeasureSleep.exe --samples $samples
$outputLines = $output -split "`n"
foreach ($line in $outputLines) {
$avgMatch = $line -match "Avg: (.*)"
$stdevMatch = $line -match "STDEV: (.*)"
if ($avgMatch) {
$avg = $matches[1] -replace "Avg: "
} elseif ($stdevMatch) {
$stdev = $matches[1] -replace "STDEV: "
}
}
"$($i), $([math]::Round([double]$avg, 3)), $($stdev)" | Out-File results.txt -Append
Stop-Process -Name "SetTimerResolution" -ErrorAction SilentlyContinue
}
Write-Host "info: results saved in results.txt"
return 0
}
$_exitCode = main
Write-Host # new line
exit $_exitCode