-
Timer vs Time()
Here is a Loop that uses Timer() to record how long a loop takes.
A second Loop used Time() to track the same loop.
The two loops record sisgnificantly different results.
Anyone care to comment as to why and which is more accurate if either. I realize there is a Timer API I could be using but this is a curiosity.
option Explicit
'
private Sub Command1_Click()
Dim strt as Single, stp as Single, x as Long
strt = time()
Do Until x = 10000000
x = x + 1
Loop
stp = time()
print "time() " & stp - strt
End Sub
'
private Sub Command2_Click()
Dim strt as Single, stp as Single, x as Long
strt = Timer
Do Until x = 10000000
x = x + 1
Loop
stp = Timer
print "Timer " & stp - strt
End Sub
John G
-
Re: Timer vs Time()
try this for command1:
Private Sub Command1_Click()
Dim strt As Date, stp As Date, x As Long
strt = Time()
Do Until x = 10000000
x = x + 1
Loop
stp = Time()
Print "time() " & CDate(stp - strt)
End Sub
hi,brt
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
</center>
-
Re: Timer vs Time()
Thanks. It certainly brought the two answers closer together. Looking for something a little more resolution that seconds though.
John G
-
Re: Timer vs Time()
This may be related:
gettickcount should be more accurated
from apiguide:
The GetTickCount function retrieves the number of milliseconds that have
elapsed since Windows was started.
'In general section
private Declare Function GetTickCount& Lib "kernel32" ()
private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'get the tickcount
ret& = GetTickCount&
MsgBox Str$(ret& / 60000) + " minutes."
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater