Suggestions for testing and timing a UDF

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
I can see at least 3 ways to code a UDF I am working on. I'd like to write another "tester/timer" UDF that will call each version a large number of times with a random combination of parameters to check for errors and to time them. Naturally, if errors are found, that version will be fixed or discarded. Of the ones that pass all tests, I would like to compare the time it took.

What is the best way to get the timings? If I understand the Timer function, it returns the time since midnight, so it only works if the code starts and stops in the same day (does not cross midnight).

What I would like to do is:
  1. Start a timer.
  2. Run the test cases against one of the versions.
  3. Stop the timer.
  4. Report the elapsed time.
  5. Repeat with the next version.
Thanks
 
I just had a quick look at the file, and I see what you've done. That start section of the class module you're referring to is actually normal, and disappears when you import the file. The key feature for this timer is actually contained in that part of the code, so yeah - all you need to do is download the file, and import it just as it is.

To get the actual file, you click on the RAW button which will take you to this URL: https://raw.githubusercontent.com/sancarn/stdVBA/master/src/stdPerformance.cls

Hope it helps!
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Also, I forgot to mention - though you will probably see it in the code - there is a feature in stdPerformance that handles the various optimisations for you as well - like ScreenUpdating, Manual Calculation settings, etc. You can either include the line:
VBA Code:
With stdPerformance.Optimise
to enable those optimisations, or simply leave it out. The code turns things back to the way they were automatically once its done. Personally, I just love that it's just a few lines of code - don't have to think about it, or reorganise my code etc.
And thank you, @GWteB for responding with the helpful explanation. Since going over this code, I'm somewhat tempted to start using the PredeclaredID element in my own class modules, though I'm sure it's easy to misuse. :)
 
Upvote 0
You are welcome @Dan_W, (I was pretty sure you'd appreciate an in-depth explanation ;) )

I'm somewhat tempted to start using the PredeclaredID element in my own class modules, though I'm sure it's easy to misuse. :)
I'm doing that very often. Misuse is lurking though and many times a cause of unexpected and sometimes apparently unexplained run-time errors. Coding against interface classes is therefore recommended.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top