Conclusions - danielep71/VBA-PERFORMANCE GitHub Wiki
[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Class-cPerformanceMonitor)
We have analyzed several methods to calculate with great accuracy and resolution time intervals in VBA.
VBA has a Timer function which is often considered unsatisfactory. However, the tests I have carried out prove the opposite.
In addition, four Windows API Functions were used, including the so-called "high-resolution timer" (QPC).
Regarding resolution, only the VBA timer and QPC can go up to hundreds of nanoseconds. The other functions are limited to milliseconds.
The accuracy of the calculation depends on the clocks included in the libraries used by the other API functions. In this latter case, it is possible to reach, depending on the case, up to 15/16 milliseconds of accuracy.
However, by implementing an additional function (“NextTick”) that allows the starting of the measurement as soon as the new tick is "triggered", the results improve significantly, obtaining, for all approaches, a maximum of 2 milliseconds of accuracy (depending on the case it can instead be exact).
The choice of one approach or another will depend on the tastes and preferences of the user since the differences are, in the end, insignificant. If you need microsecond measurements up to nanoseconds, then the Timer function and the QPC are the only ways forward. If, on the other hand, milliseconds are sufficient, the getTickCount function is the most accurate from the tests carried out.
Summary table
[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Class-cPerformanceMonitor)