Click to See Complete Forum and Search --> : Timer vs Time()


John G Duffy
August 24th, 2001, 08:32 AM
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

berta
August 24th, 2001, 08:49 AM
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/images/bertaplanet.gif'>
</center>

John G Duffy
August 24th, 2001, 08:55 AM
Thanks. It certainly brought the two answers closer together. Looking for something a little more resolution that seconds though.


John G

Cimperiali
August 24th, 2001, 09:48 AM
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: KPDTeam@Allapi.net
'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