Entwickler-Ecke

Sonstiges (Delphi) - GetTickCount


mimi - Mo 24.02.03 12:54
Titel: GetTickCount
Hallo,
wie kann ich den wert den GetTickCount(in MS) zurück liefrt in Sekunden und minuten und Stunden um rechnen ?
habe das noch nicht geschaft :evil:


Delete - Mo 24.02.03 13:21


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function FormatTime(t: int64): string;  { (gettime by Assarbad) }
begin
  //result := IntToStr(t mod 1000);
  case t mod 1000 < 100 of
    true: result := {'0' +} result;
  end;
  t := t div 1000; // -> seconds
  {result := IntToStr(t mod 60) + ' Sekunden ' + result;
  case t mod 60 < 10 of
    true: result := '0' + result;
  end;}
  t := t div 60; //minutes
  result := IntToStr(t mod 60) + ' Min ' + result;
  case t mod 60 < 10 of
    true: result := '0' + result;
  end;
  t := t div 60; //hours
  result := IntToStr(t mod 24) + ' Std ' + result;
  case t mod 60 < 10 of
    true: result := '0' + result;
  end;
  result := IntToStr(t div 24) + ' T ' + result;
end;

Ich abe da allerdings etwas dranrumgefummelt. Mußt du mal sehen, wie du das machst.


mimi - Mo 24.02.03 13:56

Danke !
Aber so richtig ist das nicht was ich suchte !
ich habe folgendes problem:
ich habe in einer lagen proceudre oben einmal in einer Variable GetTickCount gepseicht dann weiter unten noch mal.
nun wollte ich nach schauen wie viel zeit vergangen ist.

also
Zeit:=Zeit1-zeit2;
nun wollte ich das in zeit Stunden, Miunten, Sekunden ist.

dann weiß ich nämlcih wie viel zeit die Procedure braucht, oder nicht ?
gibt es noch einen bessern bzw. einfachern weg ?


AndyB - Mo 24.02.03 14:19

@Luckie: Kennt Assarbad keine if-Anweisung, oder was soll der Blödsinn mit den case-Anweisungen?


Zitat:
Aber so richtig ist das nicht was ich suchte !

Wie nicht?

Quelltext
1:
2:
3:
4:
5:
var a, b: Cardinal;
a := GetTickCount;
...
b := GetTickCount - a;
ShowMessage('Dauer: ' + FormatTime(b));


mimi - Mo 24.02.03 14:29

Ja danke !
Genau das was ich habe wollten ;)

gibt es noch ne andre möglichkeit ?
zu messen wie lange die procedure braucht ?


mars - Mo 24.02.03 20:29

Doch, gibt es schon. Erst letzthin erwähnte irgend jemand QueryPerformanceCounter(), was vor allem auch viel genauer ist.


mimi - Mo 24.02.03 20:41

und was erwarete sie als Parameter ???
ich bin aus der OH nicht schlau geworden !


mars - Mo 24.02.03 23:49

Beispielcode:

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.Button1Click(Sender: TObject);
var
  start,stop1,stop2,freq:int64;
  i:integer;
begin
  screen.cursor:=crHourGlass; {show busy cursor}
  QueryPerformanceFrequency(freq); {Get frequency} 

  QueryPerformanceCounter(start); {Get initial count}
  
  for i:=1 to 1000000 do;  {empty loop}
  QueryPerformanceCounter(stop1); {Get 1st end count}
  for i:=1 to 1000000 do application.processmessages; {do it loop}
  QueryPerformanceCounter(stop2);  {Get 2nd end count}
  screen.cursor:=crDefault;  {show normal cursor}
  If freq>0  {Display (loop2 count - loop1 count)/freq  

                   to get time in microseconds}
  then showmessage('Time for a call to  processmessages is '
                     + inttostr(((stop2-stop1)-(stop1-start)) div freq)
                     +' microseconds')
  else showmessage('No hardware timer available');
end;


Hoffe geholfen zu haben


mimi - Di 25.02.03 19:13

Danke !