Measure - danielep71/VBA-PERFORMANCE GitHub Wiki

[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Previous-|-Measure) | Next


When testing your code, it can be helpful to analyze the various routines to identify and eliminate any bottlenecks.

The first step in resolving the problem is isolating the slow code section. In order to record elapsed time, we need an accurate function to track time.

This class will help you monitor the timing and performance of VBA procedures, to improve the algorithm’s efficiency and analyze the speed of different sections of code to determine where bottlenecks exist and improvements are required.

The VBA functions Now() (and the related Date() and Time() ) are only accurate to one second. Neither of these is detailed enough (unless it is repeated many times) to time VBA routines which processes run much faster.

Fortunately, there are several clocks we can use with VBA. Each clock has different-sized “ticks” (more usually called its resolution), and the size of the tick is the smallest amount of time you can measure.

VBA often offers the possibility to perform the same task in different ways. In this class, I am going to use the most common approaches to compare results and understand the pros and cons of each one of them:

  1. VBA Timer;
  2. GetTickCount API;
  3. timeGetTime API;
  4. TimeGetSystemTime API;
  5. QueryPerformanceCounter (QPC) (sometimes called “micro-timer”)
  6. VBA Now()

Ideally, this class can measure up to hundreds of nanoseconds (1/10,000,000 seconds).


Home