I noticed in How fast can we compute the dot product? that GetTickCount was being used for timing code.
From SDK docs
The system timer on my machine ticks at 64Hz ie 15.625ms per tick.
On running
I get
I chose 1006ms deliberately to emphasize the influence of the system timer.
With code sections in the 100ms range and less the results are very poor.
For accurate timings I would suggest the above timer macros or TIX if you prefer [CC5 and/or PB9].
From SDK docs
The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer.
On running
Code:
#Compile Exe #Register None #Dim All #TOOLS OFF %NOMMIDS = 1 %NOGDI = 1 #Include "WIN32API.INC" '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global qFreq, qOverhead, qStart, qStop As Quad Global f As String Macro InitializeTimer f = "#####.######" QueryPerformanceFrequency qFreq QueryPerformanceCounter qStart ' Intel suggestion. First use may be suspect QueryPerformanceCounter qStart ' So, wack it twice <smile> QueryPerformanceCounter qStop qOverhead = qStop - qStart ' Relatively small End Macro Macro StartTimer = QueryPerformanceCounter qStart Macro StopTimer = QueryPerformanceCounter qStop Macro sTimeTaken = Using$(f,(qStop - qStart - qOverhead)*1000/qFreq) + "ms" Macro nTimeTaken = (qStop - qStart - qOverhead)*1000/qFreq '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function PBMain() As Long Local first, second, NumberOfms, i As Long, test As Quad InitializeTimer NumberOfms = 1006 test = qFreq * NumberOfms For i = 1 To 5 first = GetTickCount ' On my machine the first call to GetTickCount is unreliable first = GetTickCount StartTimer Do StopTimer If (qStop - qStart - qOverhead) * 1000 >= test Then Exit Loop second = GetTickCount Loop Print second - first;" ";sTimeTaken Next Print : Print "Done" Waitkey$ End Function
Code:
1000 1006.000060ms 1000 1006.000090ms 1015 1006.000075ms 1000 1006.000041ms 1016 1006.000116ms
With code sections in the 100ms range and less the results are very poor.
For accurate timings I would suggest the above timer macros or TIX if you prefer [CC5 and/or PB9].
Comment