Popis:
VB mß sice funkci, kterß je schopna pracovat s urΦit²m pom∞rn∞
p°esn²m rozliÜenφm, ale souΦasn² modernφ hardware umo₧≥uje pou₧φvat
timer s velik²m stupn∞m rozliÜenφ. StaΦφ na to jen pßr API:
Private Declare
Function QueryPerformanceFrequencyAny Lib _
"kernel32" Alias "QueryPerformanceFrequency"
_
(lpFrequency As Any) As Long
Private Declare Function QueryPerformanceCounterAny Lib _
"kernel32" Alias "QueryPerformanceCounter"
_
(lpPerformanceCount As Any) As Long
P°i pou₧itφ t∞chto
funkcφ ale narß₧φme na jeden problΘm. Funkce pou₧φvajφ 64-bitov²
Long Integer v parametrech, ale to VB neumφ. Nechß se to obejφt pom∞rn∞
jednoduch²m trikem - typ Currency je taky 64-bitov², akorßt jej VB pou₧φvß
trochu jinak, co₧ v tomto p°φpad∞ nevadφ:
Private
Sub Command1_Click()
Dim frequency As Currency
Dim startTime As Currency
Dim endTime As Currency
Dim result As Double
' Zjistφme si poΦφtadlo frekvence
' Vracφ 0 pokud hardware tento counter nepodporuje
If QueryPerformanceFrequencyAny(frequency) = 0 Then
MsgBox "Tento poΦφtaΦ to
nepodporuje !!!", vbCritical
Exit Sub
End If
' start Φasovßnφ
QueryPerformanceCounterAny startTime
' zde n∞jak² k≤d, kter² se mß vykonat ...
Dim i As Long
For i = 1 To 1000000
Next
' konec Φasu
QueryPerformanceCounterAny endTime
result = (endTime - startTime) / frequency
MsgBox result
End Sub
|