VBA – Timer to Benchmark Code
VBA Timer to Benchmark Code
If you are looking to benchmark re-written code or debate “quicker” methods in VBA you can use VBA’s built-in timer. Setting a variable equal to the timer at the start of your code and subtracting this from the timer at the end will give you a good estimate of how long a piece of code takes to run.
Performance may be affected by other programs running or trying to run while you’re macro is active, among other things.
The following example was used to see how long it would take to write the word “test” to cell A1 on Sheet1 a half million times. It took 21 seconds on my machine.
Dim Count As Long
Dim BenchMark As Double
BenchMark = Timer
'Start of Code to Test
For Count = 1 To 500000
Sheet1.Cells(1, 1) = "test"
'End of Code to Test
MsgBox Timer - BenchMark
If your code is running slow, try speeding it up by disabling screen updating.
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
Did you find this VBA tutorial useful? Then share it with your friends and colleagues: