timer vs GetTickCount64 precision
-
- Posts: 4307
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: timer vs GetTickCount64 precision
NtDelayExecution takes input in units of 100 nanoseconds but does not have a resolution of 100ns - it uses the system clock at 64Hz. A lot of the Windows APIs refer to '100-nanosecond intervals' but none of them actually have a resolution of 100ns.
Re: timer vs GetTickCount64 precision
I doubt that, because I get a 1ms resolution, see Delay untildeltarho[1859] wrote:NtDelayExecution ... uses the system clock at 64Hz.
-
- Posts: 4307
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: timer vs GetTickCount64 precision
NtDelayExecution definitely uses the system clock.
With the following code I get:-
Forcing the system clock to use a 1ms resolution by uncommenting the SmallTimerInterval lines I get:-
That is between 3ms and 4ms and what we would expect with a 1ms resolution.
Added: I noticed in your results 'resCurrent 10000'. What was the timer interval doing at 1ms? Did you have your browser open at the time?
With the following code I get:-
Code: Select all
6.084800001637802
13.26120000511111
14.85239999531274
14.74900000156509
14.29649999931115
14.50480000237775
14.3206999982155
14.6715999979179
14.66070000087427
14.74249999782984
Code: Select all
3.999900001957712
3.1915000062952
3.470800003732677
3.513500002419789
3.236100004784248
3.389699993242346
3.519999999298307
3.423200002700355
3.569899996065828
3.563600006252443
Code: Select all
Declare Function NtDelayExecution Lib "ntdll.dll" Alias "NtDelayExecution" (Byval dwAlertable As Ulong, Byval qInterval As Ulongint Ptr) As Long
'Declare Function SmallTimerInterval Lib "winmm" Alias "timeBeginPeriod"(As Ulong=1) As Long
'SmallTimerInterval
Dim As Double t
Dim As Ulongint delay = -30000 ' 3ms, minus for a relative delay
For i As Ulong = 1 To 10
t = Timer
NtDelayExecution( 0, Cast( Ulongint Ptr, @delay ) )
t = Timer - t
Print t*1000 ' ms
Next
Sleep
Re: timer vs GetTickCount64 precision
Oops, I had forgotten that I use NtSetTimerResolution(10000, ...). So you are most probably right. If I remember correctly, the difference between timeBeginPeriod and NtSetTimerResolution is that the latter does not set it permanently; ExitProcess restores the previous setting. But don't trust me on that, it's been a while, and right now I am too busy investigating.deltarho[1859] wrote:NtDelayExecution definitely uses the system clock.
...
I noticed in your results 'resCurrent 10000'. What was the timer interval doing at 1ms? Did you have your browser open at the time
-
- Posts: 4307
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: timer vs GetTickCount64 precision
timeBeginPeriod does not set a resolution permanently either. If we neglect to employ timeEndPeriod during an application session Windows will revoke timeBeginPeriod on closing. MSDN does not tell us that. timeBeginPeriod is a wrapper for NtSetTimerResolution but is restricted to a subset of the integral values between 1ms and 15.625ms. A lot of APIs are dumbed-downed versions of Nt* functions and why the Nt* functions are not documented.