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.
- 10 Oct 2020
- 01 Jul 2020
- 06 Apr 2020
- 11 Mar 2020
- 15 Feb 2020
Recent on Build5Nines.com
- 04 Dec 2020
Latest Cloud News: Apple on K8s, IoT, Microsoft Pluton and more! (November 20, 2020 Build5Nines Weekly)20 Nov 2020
Latest Cloud News: .NET 5 Released, Apple Silicon M1 CPU, and more! (November 12, 2020 Build5Nines Weekly)12 Nov 2020
- 11 Nov 2020
Latest Cloud News: Kubernetes, Terraform, Teams Multi-Login and more! (November 5, 2020 Build5Nines Weekly)05 Nov 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.