Writing code the first time usually does get the job done, but it may not be the best, or fastest way to do it. Sometimes you want to make it run faster, but you don’t have a way of seeing actually how fast that code runs. Or if it even runs faster after the changes you make, like you want it to. Well, heres an example of how to time parts of your code.
Insert this before the code that your unsure about:
Dim dblStart as Double Dim dblEnd as Double Dim i as Long dblStart = Timer 'Get the start time.
Then put your code that you want to test the speed of.
Then put this code after:
dblEnd = Timer 'Get the end time. Debug.Print dblEnd - dblStart 'Display the elapsed time
And that is how to test the performance of your code.
This example uses the default property of VB’s Timer class to time the execution of the routine within the loop. By placing your code inside you can quickly compare the performance of that code before and after you make those changes that are supposed to speed it up a little.
Make sure you run each version of your changes a few times to get an average time.
This should work with any version of Visual Basic.
- 01 Jul 2020
- 06 Apr 2020
- 11 Mar 2020
- 15 Feb 2020
- 02 Jan 2020
Recent on Build5Nines.com
Latest Cloud News: Azure Dev Guide eBook, xCloud, Cloud Shell + VNet and more! (August 11, 2020 – Build5Nines Weekly)11 Aug 2020
- 07 Aug 2020
Latest Cloud News: Azure Cloud Shell Tips, Azure Sphere, Microsoft acquire TikTok, NVidia acquire ARM, and more! (August 6, 2020 – Build5Nines Weekly)06 Aug 2020
- 01 Aug 2020
This site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. We also participates in affiliate programs with Udemy, and other sites. This site is compensated for referring traffic and business to these companies.