Autor Beitrag
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Fr 26.11.04 19:18 
Hi @ all,
wie kann ich messen wie lange eine Funktion dauert?
Bsp.:

ausblenden Delphi-Quelltext
1:
2:
3:
for i := 0 to 500000 do begin
...
end;


ich würde gerne messen, wie lange das dauert!

ScorpionKing

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

_________________
Aus dem Urlaub zurück!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 26.11.04 19:27 
Hallo!

Speichere die Zeit vorher und nachher. Die Differenz ist die Laufzeit. Die Zeit bekommst Du am Besten mittels "GetTickCount", dann sind die Werte in Millisekunden.

MfG
Christian

//edit: Bitte demnäcsht Delphi-Tags benutzen! Danke! :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Loki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 34

Win XP Home

BeitragVerfasst: Fr 26.11.04 19:28 
Also ich würde sagen du musst vor der Schleife und nach der Schleife GetTickCount aufrufen und in 2 Variablen speichern und dann von der Endzeit die Startzeit abziehen. Dann hast du die Zeit die deine Funktion braucht in Millisekunden.

MFG

Loki

/EDIT: Zu langsam :D
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 26.11.04 19:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Start := GetTickCount; // Millisekunden seit Systemstart

... // deine Funktion

Ende := GetTickCount; // Millisekunden seit Systemstart

Rechnung := Ende - Start // Ergebniss in Millisekunden

Ergebniss := Rechnung / 1000 // Ergebniss in Sekunden


EDIT: So stimmts.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 26.11.04 20:15 
GTA-Place hat folgendes geschrieben:
EDIT: So stimmts.
Nicht ganz. Ergebnis nur mit einem "s" am Ende ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 26.11.04 20:18 
Hab grad im anderen Thread gedacht:
"Irgendwie sieht 'Ergebniss' komisch aus... Ach, man schreibts ja nur mit einem 's'" ^^
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Sa 27.11.04 07:10 
Bei mir funktioniert da aber irgendwie nicht!

_________________
Aus dem Urlaub zurück!
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 27.11.04 08:51 
Irgendwelche Fehler?
Bei mir gehts.
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Sa 27.11.04 15:33 
sorry, klappt bei mir auch.
die funktion die ich messen wollte war einfach zu schnell, deshalb kam raus: dauer: 0 ms!

:D

_________________
Aus dem Urlaub zurück!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 27.11.04 17:31 
Für ganz schnelle Funktionen gibt's immernoch QueryPerformanceCounter:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
    Start, Ende, Freq: Int64;
    Dauer: Extended;
begin
    QueryPerformanceCounter(Start);
    ...  //Hier deine sehr schnelle Routine
    QueryPerformanceCounter(Ende);
    QueryPerformanceFrequency(Freq);
    Dauer := (Ende - Start) / Freq;
end;


Funktioniert je nach Hardware-Timer bis auf einen Taktzyklus genau, bei einigen Boards aber auch nur knapp 3 MHz.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ScorpionKing Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Di 30.11.04 14:46 
danke!
es geht ja jetzt!

_________________
Aus dem Urlaub zurück!
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Di 30.11.04 15:21 
Zitat:
QueryPerformanceCounter
:?:
ab welcher delphi-version ist dieser denn implementiert?
mein D4 kennt ihn leider nicht...

mfg, stefan
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 30.11.04 15:28 
Unit Windows.pas eingebunden?
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Do 02.12.04 10:55 
klar, die binde ich ja nie aus :D
mittlerweile hab ich auch schon die hilfe dazu gefunden -
einfach QueryPerformanceCounter hintippen & F1 drücken :wink: