Autor Beitrag
G-McKree
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Di 27.12.05 13:43 
Problem:
Ich bastel da so an einem Programm (wie immer nichts sinnvolles) und da geht es im Prinzip darum 3 Variablen (Zahlen) zu vergleichen um zu wissen welche die größte ist. So siehts bei mir aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
...
  if (dA < dB) and (dA < dC)  then
    image1.Canvas.Pixels[x,y]:= clRed
  else if (dB < dA) and (dB < dC) then
    image1.Canvas.Pixels[x,y]:= clBlue
  else if (dC < dB) and (dC < dB) then
    image1.Canvas.Pixels[x,y]:= clGreen;
...


Frage:
Kann ich die Variablen anders (schneller) vergleichen?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 27.12.05 13:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
max := dA;
Farbe := clred;
if dB > max then 
begin
  max := dB;
  Farbe := clgreen;
end;
if dC > max then 
begin 
  max := dC;
  Farbe := clblue;
end;
image1.Canvas.Pixels[x,y] := Farbe;

_________________
We are, we were and will not be.
G-McKree Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178



BeitragVerfasst: Di 27.12.05 14:12 
danke, aber ist das auch schneller?

(wie kann ich das eigentlich messen? ich klick immer aufn button und schätze das dann ab)
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Di 27.12.05 14:14 
statt vieler Ifs, was hälst du von sortieren?
grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 27.12.05 14:19 
Wenn das nur einmal ausgeführt wird, dürfte es kaum einen Geschwindigkeitsunterschied geben. Meine Variante kommt mit weniger Vergleichen aus, braucht aber mehr Zuweisungen. Ob jetzt eine Zuweisung oder ein Variablenvergleich mehr Prozessorttakte benötigt, kann ich nicht sagen.

Die drei Zahlen zu sortieren dürfte wenig sinnvoll sein.

_________________
We are, we were and will not be.
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: Di 27.12.05 14:44 
MOV (Zuweisung) 3 Takte bei Speicherzugriff, 1 ohne.
CMP 3 Takte IIRC.

Insgesamt sind es bei Gausi aber
1. weniger Vegleiche
2. Weniger Property-Zuweisungen
Wodurch Gausi's Source um 50-100% schneller sein sollte.

_________________
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.