Is there code in VBA I can wrap a function with that will let me know the time it took to run, so that I can compare the different running times of functions?
相关问题
- Faster loop: foreach vs some (performance of jsper
- Why wrapping a function into a lambda potentially
- Ado.net performance:What does SNIReadSync do?
- Device support warning : Google play 2019
- Error handling only works once
相关文章
- Optimization techniques for backtracking regex imp
- Profiling Django with PyCharm
- Web Test recorder does not allow me to record a te
- Factory_girl has_one relation with validates_prese
- DOM penalty of using html attributes
- Which is faster, pointer access or reference acces
- What is the difference between `assert_frame_equal
- Django is sooo slow? errno 32 broken pipe? dcramer
We've used a solution based on timeGetTime in winmm.dll for millisecond accuracy for many years. See http://www.aboutvb.de/kom/artikel/komstopwatch.htm
The article is in German, but the code in the download (a VBA class wrapping the dll function call) is simple enough to use and understand without being able to read the article.
For newbees, these links explains how to do an automatic profiling of all the subs that you want to time monitor :
http://www.nullskull.com/a/1602/profiling-and-optimizing-vba.aspx
http://sites.mcpher.com/share/Home/excelquirks/optimizationlink see procProfiler.zip in http://sites.mcpher.com/share/Home/excelquirks/downlable-items
Unless your functions are very slow, you're going to need a very high-resolution timer. The most accurate one I know is
QueryPerformanceCounter
. Google it for more info. Try pushing the following into a class, call itCTimer
say, then you can make an instance somewhere global and just call.StartCounter
and.TimeElapsed
The Timer function in VBA gives you the number of seconds elapsed since midnight, to 1/100 of a second.
If you need greater resolution, I would simply run the function 1,000 times and divide the total time by 1,000.
If you are trying to return the time like a stopwatch you could use the following API which returns the time in milliseconds since system startup:
after http://www.pcreview.co.uk/forums/grab-time-milliseconds-included-vba-t994765.html (as timeGetTime in winmm.dll was not working for me and QueryPerformanceCounter was too complicated for the task needed)