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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing A Loop 1

Status
Not open for further replies.

Denk

Programmer
Jan 4, 2000
22
0
0
GB
I am trying to work out the most efficient method of timing a Do..Loop routine. Basically what i want to do is be able to display the amount of time in hours and seconds it has taken to complete the loop.<br><br>Any help would be appreciated.
 
well, have you ever tried a timer function? Cause visual basic has this, you can probally set the timer to 1 second intervals, then have it update a label everytime, until it reaches, or it subtracts the value to the desired limit, then you can disable the timer. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
try<br><FONT FACE=monospace><b><br>Dim i as long, d1 as date, d2 as date<br><br>d1 = now<br><br>for i = 0 to 100000<br>&nbsp;&nbsp;doevents<br>next i<br><br>d2 = now<br><br>msgbox &quot;loop took: &quot; & format(d2-d1,&quot;hh:mm:ss&quot;)<br></font></b><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
Thanks Michael, your solution worked well.
 
I use timing routines regularly in machine control code. Much to my amazement, I recently discovered the routine our company had been using for delays, timeouts, etc. was only accurate to 10 Msec. If we asked for a delay of 1 Msec - we got 10.....If we asked for 5 Msec - we got 10. I stumbled across an article in the MS Knowledge Base that talked about using the QueryPerformanceTimer. Thek KB article was #Q172338. This article provided me with sufficient information to to rework our timing routines to provide a major accuracy improvement. If your timing has to be this tight, check out this article.
 
Timing and it's accuracy has been discussed many times, and in great detail, in this forum. The following thread discusses and illustrates most of the approaches (with increasing timer accuracy as you work through the thread): thread222-274248
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top