So this question is two parts. The first is seeing whether there is a quick and simple code that I can incorporate into my current sub to check how fast the sub will take to run. I just need precision down to seconds, and up to maybe a couple of minutes.
The 2nd is I am currently trying to optimize the run time of my sub. It is a search function that allows a user to specify which variables to select to search for and displays the results on the following worksheet. I’ve surfed the net and I’ve done the following general applications to speed up my program
- disable screen updating at the beginning of my sub
- avoid copy&paste to clipboard as much as possible
However, my program still takes ~5 to 10 seconds to run everytime the user runs a search. I would like to decrease this time as much as possible.
I realize without looking at my code it is hard to give specific suggestions, but I am currently just looking for general suggestions. If it is still slow after the general principles have been implemented I will post my code here.
My search program is a linear search program and stores the values into an array. My search function can accomodate up to 4 search variables though and I store each search into an array and I consolidate the array at the end into a final results array.
I generally use the GetTickCount API function. As long as you’re not intending to measure time over weeks or months it should be accurate. Below is an example that shows different looping measures being timed. 1 tick = 1ms