Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer function to find bottlenecks in code

Status
Not open for further replies.

claudebo

Programmer
May 17, 2002
8
US

I would like to create a timer to find bottlenecks in forms queries and code and also to try different code snippets.
Any ideas on how to do this?

thanks

Claude
 
Create two public variables on your form (Dim sTime as long, eTime as long)
When the code starts .. sTime = Time()
When the code stops.. eTime = time()

Then stick the results of sTime-oTime in a text box..

What you need?

------------------------
Hit any User to continue
 
First question is how precise do you want your timings to be? For example, using the built-in Time function will provide you resolutions to about 1/100 of a second. Using the GetTickCount API will get you into about the 55 millisecond range, and for even better timings, the QueryPerformanceCounter can get you into the 4-6 microsecond range.

That being said, the test the speed of various code snippets, you need to have a good test environment set up. Windows does lots of things in the background, such as buffer flushing, or other applications, such as Outlook, may periodically check for, or download mail. If any of these things happen while you running your timer tests, your results will be skewed. You also need to be aware of cacheing issues. You need to take every possible precaution to ensure that nothing can happen in the background while your testing, and then structure your code so that you timing exactly what you want to time. Also, run the tests many times and average the results.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top