Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 24.10.07 15:59 
Ich möchte ein Programm starten und dann in Delphi dessen Laufzeit ständig angezeigt bekommen
Und das im Format hh:mm
Ich habe GetTickCount und QueryPerformanceCounter gefunden

Bei GetTickCount ist aber das Problem, das es bei rechenintensiven Programmen (wie meins eins ist) verfälscht werden kann
Warum?

Bei QueryPerformanceCounter könnte es die Ausführgeschwindigkeit beeinträchtigen (da hoher ressourcenverbrauch)
Quelle: www.dsdt.info/tipps/?id=53

Was ist da dran?
Was sollte ich verwenden (hab schon daran gedacht vlt mit Now zu arbeiten
würde das gehen?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 24.10.07 16:08 
Moin!

Was spricht denn gegen die Systemzeit beim Start zu merken und dann die Differenz zu Now zu bestimmen? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 24.10.07 16:20 
also so:
ausblenden Delphi-Quelltext
1:
2:
3:
start:=Now;
...
ende:=Now;


Ok und dann?
wie wandle ich das dann um?
War das nicht eine float zahl mit tagen vorm komma?
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 24.10.07 18:50 
ich glaub die kann man einfach abziehen:

ausblenden Delphi-Quelltext
1:
2:
3:
runtime := stop - start;

label1.caption := FormatDateTime('hh:mm:ss');


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mi 24.10.07 19:23 
Ich mach' des immer so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
function Seconds: Double;
var
  Hour, Min, Sec, MSec: Word;
begin
  DecodeTime(Now, Hour, Min, Sec, MSec);
  Seconds := 3600 * Hour + 60 * Min + sec + MSec / 1000;
end;

[..]

var
start, stop, total: double;
begin
  Start := Seconds;
  // mach ma' was Computer
  Stop := Seconds;
  total := stop - start;
  
  if total <= 60 then
    writeln(' Benötigte Zeit: ', total:4:1' Sekunden');
  if (total > 60and (total <= 3600then
    writeln(' Benötigte Zeit: ', (total/60):4:1' Minuten');
  if total > 3600 then
    writeln(' Benötigte Zeit: ', (total/3600):5:2' Stunden');
end;


Gruß

Calculon
--
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Mi 24.10.07 19:26 
Hi FlameFire, hier mal ne Proc, die die Windows-Uptime ausgibt.
Sollte ja nicht so schwer sein, das umzustricken für deinen Zweck:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
function UpTime: string;
const
  ticksperday : Cardinal = 1000 * 60 * 60 * 24;
  ticksperhour : Cardinal = 1000 * 60 * 60;
  ticksperminute : Cardinal = 1000 * 60;
  tickspersecond : Cardinal = 1000;
var
  t : longword;
  d, h, m, s : Cardinal;
begin
  t := GetTickCount;
  d := t div ticksperday;
  dec(t, d * ticksperday);
  h := t div ticksperhour;
  dec(t, h * ticksperhour);
  m := t div ticksperminute;
  dec(t, m * ticksperminute);
  s := t div tickspersecond;
  Result := 'Windows-Uptime: '+IntToStr(d)+ ' Tage '+IntToStr(h)+' Stunden '+IntToStr(m)+' Minuten '+IntToStr(s)+' Sekunden';
end;

Da könnte man eine Function (ZeigeZeit) draus machen, der man Millisekunden (wie sie GetTickCount liefert) übergibt und als formatierten String ausgibt.
Also etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var Start, AktuelleZeit: Cardinal;

//beim Programmstart:
  Start:=GetTickCount;

//irgndwann, wenn es ausgegeben werden soll:
  AktuelleZeit:=GetTickCount-Start;
  LabelX.Caption:=ZeigeZeit(AktuelleZeit);

_________________
Wir haben für jede Lösung das richtige Problem ;)
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 25.10.07 14:30 
ok danke
ich glaube das sind genug lösungen
hab dann die von elundril genommen weils die einfachste ist

warum macht man das nicht immer so?
man kann ganz leicht alle daten anzeigen und mit *24*3600 hat man auch die sekunden wenn man sie braucht samt ms
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Do 25.10.07 15:01 
Mach's doch mit Sleep()! Und pro Sekunde zählst du dann eben 1012/1011/1013 ms dazu! :roll: [mach ich bei meinem Reaktionszeitmesser auch so!