Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 02.03.07 23:06 
Wie kann man die Zeit messen, die ein Algorithmus braucht? Am besten in ms. ;) Macht man so etwas mit GetTickCount?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 02.03.07 23:11 
Kann man machen, ja. Allerdings sagt das relativ wenig über die "Güte" eines Algorithmus aus. Dafür sind theoretische Analysen eher geeignet. Zum Beispiel indem man abschätzt, wieviele Vergleiche/Vertauschungen maximal/im Durchschnitt (bei Sortieralgorithmen) durchgeführt werden, bis man fertig ist.

_________________
We are, we were and will not be.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 02.03.07 23:14 
@Gausi: Du studierst doch Informatik, oder? Wo bekommt man das Spezialwissen her, um einen Algorithmus zu bewerten? Links? Literatur?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 02.03.07 23:23 
Auf Anhieb kann ich dich nur mit ein paar Wikpedia-Links totschlagen.

Laufzeiten von Algorithmen werden i.A. im O-Kalkül angegeben. Man betrachtet meistens die asymptotische Laufzeit, d.h. man ist daran interessiert, was passiert wenn die Eingabe sehr groß wird (weil man z.B. drölftausend Zahlen sortieren will).

Ansonsten: Etwas gesunder Menschenverstand und etwas Mathematik hilft da auch schon. Wenn man so was hat wie
ausblenden Delphi-Quelltext
1:
2:
3:
4:
 
for i := 1 to n do
  for j := i to n do
    //machwas
dann sind das n + (n-1) + (n-2) + ... 2 + 1 viele Schritte. Der kleine Gauß hat das mal in der Schule ausgerechnet, das sind n*(n+1)/2. Im besagten O-Kalkül lässt man Konstanten weg (kauft man sich halt nen Rechner, der doppelt so schnell ist). Das wären dann als O(n^2) viele Schritte. Der Bubblesort funktioniert in etwa so.

_________________
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: Fr 02.03.07 23:25 
In Bezug auf die Güte von Algorithmen gibt es mehrere Dinge:
1. Man rechnet selber (geht für einfache Algos recht einfach ... Für Kompliziertere muss man ggf. Erzeugende Funktionen, Differential-Gleichungen uns andere Grausamkeiten lösen
ODER man vertraut auf
2. schaut in die Wiki oder andere erGOOGLEte Quellen, die den Algorithmus behandeln.

Also gerade so, wie's user profile iconGausi in diesem mir grad orange angezeigten Posting erklärt hat ;-)

_________________
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.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 02.03.07 23:31 
user profile iconBenBE hat folgendes geschrieben:
1. Man rechnet selber

Was mache ich denn, wenn ich keine for-Schleifen verwende?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Sa 03.03.07 10:42 
user profile iconMarco D. hat folgendes geschrieben:
user profile iconBenBE hat folgendes geschrieben:
1. Man rechnet selber

Was mache ich denn, wenn ich keine for-Schleifen verwende?

Ohne Schleifen hast du immer O(1). Außer es wird rekursiv. Dann kanns lustig werden. Siehe z.B. meine Facharbeit

mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 10.03.07 14:21 
Und wenn es mir nur um die reine Laufzeit geht?
Macht man dass dann so, dass man vor dem Algo GetTickCount aufruft, dann den Algo startet, dann wieder GetTickCount aufruft und die Differenz der beiden Zahlen entspricht dann der Laufzeit?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Sa 10.03.07 14:39 
user profile iconMarco D. hat folgendes geschrieben:
Und wenn es mir nur um die reine Laufzeit geht?
Macht man dass dann so, dass man vor dem Algo GetTickCount aufruft, dann den Algo startet, dann wieder GetTickCount aufruft und die Differenz der beiden Zahlen entspricht dann der Laufzeit?
Jo genau, wobei die ja Rechnerspezifisch ist. Sinnvoller ist es die Takte zu messen (ich glaube das geht mit QueryPerformanceCount) oder eben wissen, wieviele Takte ein Befehl hat (das kenn ich von µC, beim PC geht das wohl eher schwer)...

Gruß Hape!
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 10.03.07 14:44 
Kannst du mir das mit den Takten genauer erklären? ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Sa 10.03.07 15:02 
Mit QueryPerformanceFrequency bekommst du die Takte pro Sekunde, mit QueryPerformanceCounter die Takte seit Systemstart . Wenn du nun den Wert zu beginn deines algos vom Wert am Ende deines algos abziehst, und diesen durch die Frequzen teilst, dann hast du eigentlich was du brauchst ;)

gruss, Rob

_________________
erare humanum est
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 10.03.07 15:08 
Okay und wenn ich nun den Wert habe. Was sagt der mir?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Sa 10.03.07 15:12 
Hmmm.. das sollte dir doch jetzt eigentlich klar sein, falls nicht. F1 -> QueryPerformanceCounter & QueryPerformanceFrequency ;)

gruss, Rob

_________________
erare humanum est
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 10.03.07 15:13 
user profile iconRobinator hat folgendes geschrieben:
Hmmm.. das sollte dir doch jetzt eigentlich klar sein, falls nicht. F1 -> QueryPerformanceCounter & QueryPerformanceFrequency ;)

gruss, Rob

Okay Frage blöd formuliert: Was sagt mit dieser Wert über den Algorithmus aus?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot