-
Notifications
You must be signed in to change notification settings - Fork 67
stdPerformance - Timer accuracy #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the example :) The only issue I do see is Mac compatibility. I don't think such a function exists on Mac OS, so will have to keep old functionality in the rework I imagine. I did consider this at the time, but wasnt totally sure whether it's worth the hassle of adding a different implementation for what is likely a minor improvement in speed tests. In the end:
Happy to accept a PR for this 👍 |
Thank you for the feedback. |
Would this be as simple as declaring the high resolution timer as shown above and then inserting a function like this (I multiplied by 1000 to keep the units at ms): `Public Function QPC() As Variant End Function` I made the pStartTime = QPC and pEndtime = QPC in the Initialize and Terminate procedures respectively and it seems to be working. |
@ThomasG08 Looks like the equivalent for mac is As to garbage collection, looks like VBA doesn't use garbage collection.
@psilosynapse To be fair, yes, though I think I'd prefer to keep backwards compatibility. Also it seems some systems don't even have QPF function: Public Function QueryTick() As Double
static Frequency as currency, QPFAvailable: if isEmpty(QPFAbailable) then QPFAvailable = QueryPerformanceFrequency(Frequency) <> 0
If QPFAvailable Then
Dim TickCount As Currency
if QueryPerformanceCounter(TickCount) = 0 then Exit Function 'At what point does this actually occur?
QueryTick = (CDec(TickCount) / CDec(Frequency)) * 1000
else
QueryTick = GetTickCount()
end if
End Function |
@sancarn, if you are still interested in this, have a look at the code I use for timing in VBA: VBA-AccurateTimer (gist) It's implemented fully cross-platform, and with the best possible performance as a goal. |
Ah cool thanks :) Glad it's doable on mac and good to see an implementation 👍 If you want to try your hand at a PR feel free, else I'll add it to my long todo list 😄 |
stdVBA/src/stdPerformance.cls
Lines 67 to 79 in 835bf4b
The GetTickCount Function is limited to the system timer accuracy, which is usually 10-15ms. An improvement of this accuracy could be achieved by using the API for the CPU-Performancecounter and -frequency.
Example:
Running TestPerformanceCounter will give a result similar to this:
10000 items - total: 50005000 - Runtime: 256,7 µs
100000 items - total: 5050055000 - Runtime: 1506,1 µs
1000000 items - total: 505050555000 - Runtime: 14867,8 µs
10000000 items - total: 50505055555000 - Runtime: 148550,2 µs
Edit: the variables for the QueryPerformanceCounter are passed in as currency, as the API-function requires a 64-bit Integer (LongLong) pointer, which is not available in VBA6. VBA6 supports the Currency Datatype, which is a 64-bit Integer with fixed comma. From VBA7 on, the LongLong Type could be used instead.
The text was updated successfully, but these errors were encountered: