Am neuen Zeitzähler hatte ich auch schon geschraubt
Include
Code: Zeitzaehler.inc
'XProfan X3.1
'$I Zeitzaehler.inc
$IFNDEF TICKCOUNTER
$DEFINE TICKCOUNTER
Def %TickCount.MicroSec 1
Def %TickCount.MS 2
Def %TickCount.Sec 3
Declare Quad TickCount.Frequency
Declare Quad TickCount.StartTime
Declare Quad TickCount.StopTime
Declare Long TickCount.DieDLL
Proc TickCount.Init
TickCount.DieDLL = UseDLL("Kernel32.DLL")
TickCount.StartTime = 0
TickCount.StopTime = 0
ImportFunc(TickCount.DieDLL,"QueryPerformanceFrequency","TickCount_QPF")
ImportFunc(TickCount.DieDLL,"QueryPerformanceCounter","TickCount_QPC")
TickCount_QPF(Addr(TickCount.Frequency))
Return TickCount.Frequency
EndProc
Proc TickCount.Exit
FreeDLL TickCount.DieDLL
EndProc
Proc TickCount.Start
TickCount_QPF(Addr(TickCount.Frequency))
TickCount_QPC(Addr(TickCount.StartTime))
Return TickCount.StartTime
EndProc
Proc TickCount.Stop
TickCount_QPC(Addr(TickCount.StopTime))
Return TickCount.StopTime
EndProc
Proc TickCount.Stopp
TickCount_QPC(Addr(TickCount.StopTime))
Return TickCount.StopTime
EndProc
// Parameter: GetTime(Einheit,stopp), GetTime(Einheit,start,stopp), GetTime(Einheit,frequ,start,stopp)
// Einheit =
// %TickCount.MicroSec == 1
// %TickCount.MS == 2
// %TickCount.Sec == 3
Proc TickCount.GetTime
Declare quad erg, start,stopp,frequ
Declare int Einheit
Select %PCount
CaseOf 2
Parameters int a0, quad a1
Einheit = a0
stopp = a1
start = TickCount.StartTime
frequ = TickCount.Frequency
CaseOf 3
Parameters int b0, quad b1,b2
Einheit = b0
start = b1
stopp = b2
frequ = TickCount.Frequency
Otherwise // 4 Parameter
Parameters int c0, quad c1,c2,c3
Einheit = c0
frequ = c1
start = c2
stopp = c3
EndSelect
Select Einheit
CaseOf %TickCount.MicroSec
erg = ((stopp - start) * 1000000) / frequ
CaseOf %TickCount.MS
erg = (((stopp - start) * 1000000) / frequ) / 1000
CaseOf %TickCount.Sec
erg = (((stopp - start) * 1000000) / frequ) / 1000000
Otherwise // Hier ist der Vorgabewert "ms"
erg = (((stopp - start) * 1000000) / frequ) / 1000
EndSelect
Return erg
EndProc
Proc TickCount.ShowTime
Parameters int Einheit,dezi, float wert
Declare string tmp,form
tmp = Trim$(Str$(dezi))
form = "%8." + if(Len(tmp)=0,"0",tmp) + "f"
Select Einheit
CaseOf %TickCount.MicroSec
form = form + " µs"
CaseOf %TickCount.MS
form = form + " ms"
CaseOf %TickCount.Sec
form = form + " sec"
Otherwise // Hier ist der Vorgabewert ""
// form = form + ""
EndSelect
Return Format$(form,wert)
EndProc
$ENDIF
Alles anzeigen
und Beispiel
Code: Test_Zeitmessung.prf
$I Zeitzaehler.inc
TickCount.Init()
cls
declare r!, s!
r! = -3.111111111111
print " ----- "
declare quad Start,Stopp,Verwaltung
' Vorab Messung des Loop-Overhead
Start = TickCount.Start()
whileloop 10000
'
endwhile
Stopp = TickCount.Stop()
Verwaltung = Stopp - Start
' Messschleife mit Zu prüfendem Algorithmus
Start = TickCount.Start()
whileloop 10000
s! = Testbit(r!,31)
endwhile
Stopp = TickCount.Stop() - Verwaltung
print TickCount.ShowTime( %TickCount.MS, 3, TickCount.GetTime(%TickCount.MS, start,stopp) ) + " netto"
print s!
TickCount.Exit()
waitinput
end
Alles anzeigen