Comments (6)
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:
- VBA already takes varying times to call DLL functions depending on computer/system
- stdPerformance already relies on garbage collection to read the end time, which may lead to randomness.
Happy to accept a PR for this 👍
from stdvba.
Thank you for the feedback.
I will do some digging on equivalent functions on Mac and will do some digging into what randomness is introduced due to garbage collection. In the end you might probably be right - if it's so important to measure sub-millisecond runtimes one should not rely on garbage collection anyway to measure the results.
If I find the results still worthwhile, I will come back with a PR.
from stdvba.
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
Dim Frequency As Currency, TickCount As Currency
If QueryPerformanceFrequency(Frequency) = 0 Or QueryPerformanceCounter(TickCount) = 0 Then Exit Function
QPC = (CDec(TickCount) / CDec(Frequency)) * 1000
End Function`
I made the pStartTime = QPC and pEndtime = QPC in the Initialize and Terminate procedures respectively and it seems to be working.
from stdvba.
@ThomasG08 Looks like the equivalent for mac is mach_absolute_time
and mach_timebase_info
I'm not certain how to declare these though (yet).
As to garbage collection, looks like VBA doesn't use garbage collection.
but VBA/Excel does not have garbage collection, like old VB. Instead of GC, it uses reference counting. Memory is freed when you set a pointer to nothing (or when variable goes out of scope). Like in old VB it means that circular references are never freed.
@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
from stdvba.
@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.
I kept it contained to one standard module for maximum portability, but it could serve you as a handy example for the more elaborate implementation in your library, especially how to use the API functions mach_absolute_time
and mach_timebase_info
on Mac.
I'm using mach_continuous_time
instead of mach_absolute_time
but they are interchangeable with the only difference being that mach_absolute_time
does not increment while the system is asleep while mach_continuous_time
does.
from stdvba.
@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. I kept it contained to one standard module for maximum portability, but it could serve you as a handy example for the more elaborate implementation in your library, especially how to use the API functions
mach_absolute_time
andmach_timebase_info
on Mac. I'm usingmach_continuous_time
instead ofmach_absolute_time
but they are interchangeable with the only difference being thatmach_absolute_time
does not increment while the system is asleep whilemach_continuous_time
does.
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 😄
from stdvba.
Related Issues (20)
- Refactor classes to use `TThis`
- stdSentry
- stdWindow - variable minStackSize is never assigned HOT 1
- VB6 vs VBA classes HOT 3
- `stdUIA` - implementation
- `stdRuntimeJS`
- Compatible Long And Longptr HOT 28
- `stdJSON` parse performance
- stdFiber - Issue when errors occur HOT 1
- stdJSON HOT 1
- stdCallback errors
- `stdWindow` - Improvements HOT 3
- stdHTTP - bug using proxy only for stdHTTP HOT 9
- stdTimer sheet reference HOT 1
- stdProcess does not parse, property closed with End Function HOT 18
- stdLambda - issue with parsing expressions?
- stdJSON issues + improvement suggestions HOT 1
- Missing variable declarations HOT 1
- stdAcc Object doesn't supported error HOT 1
- `stdImage` improvements HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stdvba.