Groups | Search | Server Info | Login | Register
Groups > microsoft.public.vb.general.discussion > #118478
| From | ObiWan <obiwan@mvps.org.invalid> |
|---|---|
| Newsgroups | microsoft.public.vb.general.discussion |
| Subject | Re: Which is better |
| Date | 2024-06-05 16:00 +0200 |
| Organization | n/a |
| Message-ID | <v3pr2j$17rfb$1@solani.org> (permalink) |
| References | (5 earlier) <v3kemr$15ggd$1@solani.org> <v3kjnc$15jbp$1@solani.org> <v3kn9n$15i2m$1@solani.org> <v3ko35$15i2m$2@solani.org> <v3nel0$1602a$1@solani.org> |
> the "timeGetTime" API returns the time in milliseconds ;-)
Otherwise you may try the following code
Option Explicit
Private Declare Function QueryPerformanceFrequency Lib "kernel32" _
(lpFrequency As Currency) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" _
(lpPerformanceCount As Currency) As Long
' calculates elapsed time
Function TimeCalc(Optional ByVal bStr As Boolean = False) As Single
Static cFreq As Currency
Static cStart As Currency
Dim cEnd As Currency
Dim fElapsed As Single
Dim lRet As Long
If bStr Then
' initialize and get current time value
lRet = QueryPerformanceFrequency(cFreq)
If lRet <> 0 Then
lRet = QueryPerformanceCounter(cStart)
Else
' performance counters not supported
TimeCalc = -1
End If
Exit Function
End If
' obtain current time and calculate elapsed time
lRet = QueryPerformanceCounter(cEnd)
fElapsed = ((cEnd - cStart)*1000/cFreq)
' return elapsed time
TimeCalc = fElapsed
End Sub
you start by calling "TimeCalc" once at startup to check if the query
performance counters are suppported
fRet = TimeCalc()
If fRet = -1 Then
' not supported !!
End If
if so you then proceed with something like
Call TimeCalc()
... do the job ...
fElapsedTime = TimeCalc(False)
and then the "fElapsedTime" will give you the elapsed time, not that
one usually needs such a granularity, but then one may never know :)
Back to microsoft.public.vb.general.discussion | Previous | Next — Previous in thread | Next in thread | Find similar
Which is better StanWeiss <srweiss1@comcast.net> - 2024-05-30 10:58 -0400
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-05-30 17:33 +0200
Re: Which is better StanWeiss <srweiss1@comcast.net> - 2024-05-31 09:07 -0400
Re: Which is better StanWeiss <srweiss1@comcast.net> - 2024-06-01 15:56 -0400
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 09:34 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 09:37 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 14:35 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 14:59 +0200
Re: Which is better StanWeiss <srweiss1@comcast.net> - 2024-06-03 10:24 -0400
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 17:25 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-03 17:39 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-04 18:16 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-05 16:00 +0200
Re: Which is better ObiWan <obiwan@mvps.org.invalid> - 2024-06-05 16:39 +0200
csiph-web