Skip to content

amitxv/TimerResolution

Repository files navigation

TimerResolution

Downloads Buy Me a Coffee

MeasureSleep is used to measure the precision of Sleep(1). By default, it sits in an infinite loop measuring the sleep deltas, but you can use the --samples argument to get average and STDEV metrics.

SetTimerResolution is used to request a higher resolution by calling NtSetTimerResolution. As an example to automatically start a hidden instance of the program when the system starts and raise the resolution to 0.5ms, place the binary somewhere safe and create a shortcut in shell:startup with the target below.

C:\SetTimerResolution.exe --resolution 5000 --no-console

Thanks to a comment on the Great Rule Change article, on Windows Server 2022+ and Windows 11+, the registry key below can also be used so that requesting a higher resolution is effective on a system-wide level rather than only the calling process.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\kernel]
"GlobalTimerResolutionRequests"=dword:00000001

Precision vs. Resolution Graph

The micro-adjust-benchmark.ps1 script can be used to automate the process of plotting precision against resolutions. The results can be visualized with chart-studio.plotly.com.

Building

git clone https://github.com/amitxv/TimerResolution.git
cd .\TimerResolution\
# x64
$env:VCPKG_DEFAULT_TRIPLET = "x64-windows"
# install dependencies
vcpkg install
# replace "SetTimerResolution" with "MeasureSleep" if desired
MSBuild.exe .\TimerResolution.sln -p:Configuration=Release -p:Platform=x64 -t:SetTimerResolution