Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mi 26.11.08 22:05 
Abend,

ich hab heute ein kleines BenchmarkTool geschrieben, was einfache Zahlenwerte ausrechnet und ausgiebt und nebenbei die verstrichen Zeit um dies zu tun berechnet.

Da ich noch ein Anfänger bin was Delphi betrifft, wollte ich fragen ob jemand Verbesserungsvorschläge hat oder Anregungen was ich noch einbauen könnte :wink:

Hier ist der gesamte Code

ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ComCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    ProgressBar1: TProgressBar;
    Label1: TLabel;
    Button3: TButton;
    GroupBox2: TGroupBox;
    Edit1: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    StringGrid2: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  maxG : Integer ;
  c : Integer ;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
s,e : Real ; //Time
i,j,max : Integer ;
begin
  inc(c);
  max := StrToInt(Edit1.Text);
  maxG := max ;
  ProgressBar1.Max := max ;
  S := GetTickCount ;
  for i := 1 to max do
    for j := 1 to max do
      begin
        StringGrid1.RowCount := i ;
        StringGrid1.ColCount := j ;
        StringGrid1.Cells[i-1,j-1]:=IntToStr(i*j);
        ProgressBar1.Position := i ;
      end;
  E := GetTickCount ;
  E := E-S ;
  Label4.Caption:=FloatToStr(E/1000)+' Sekunden';
  StringGrid2.RowCount := c+1 ;
  StringGrid2.Cells[0,c]:=IntToStr(c);
  StringGrid2.Cells[1,c]:=FloatToStr(E/1000);
  StringGrid2.Cells[2,c]:=IntToStr(MaxG);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,j : Integer ;
begin
  for i := 1 to maxG do
    for j := 1 to maxG do
      begin
        StringGrid1.Cells[i-1,j-1]:='';
      end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Form1.Close ;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ProgressBar1.Min := 0 ;
  StringGrid2.Cells[0,0]:='Run';
  StringGrid2.Cells[1,0]:='Time';
  StringGrid2.Cells[2,0]:='Max';
end;

end.



Grüße GericasS :wink:
Einloggen, um Attachments anzusehen!
_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mi 26.11.08 22:27 
Für den Anfang: Eine kleine Beschreibung und ein jederzeit ansprechbares Programm. ;)

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 26.11.08 22:35 
Ich denke, in Zeiten wo die meisten neuen Computer mehr als einen Kern haben, sollte man auch alle Kerne mit der Aufgabe beschäftigen :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Do 27.11.08 09:22 
Such im Forum mal nach QueryPerformanceCounter und QueryPerformanceFrequcency. Das wäre schon mal ein Anfang...
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 27.11.08 11:33 
Ebenfalls wäre ein Application.ProcessMessage alle, sagen wir, 1000 schleifendurchläufe damit die fortschrittsanzeige auch was anzeigt und das (Keine Rückmeldung) ausbleibt vielleicht angebracht. ( if i mod 1000 = 0 then Application.ProcessMessages; heißt die Zauberzeile :zustimm: )

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
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 27.11.08 17:59 
user profile iconChristian S. hat folgendes geschrieben Zum zitierten Posting springen:
Ich denke, in Zeiten wo die meisten neuen Computer mehr als einen Kern haben, sollte man auch alle Kerne mit der Aufgabe beschäftigen :-)


Ich zum Beispiel nicht :evil:

@ JayEff: Wieso if i mod 1000 = 0? Müsste das nicht if i mod 1000 = 1 heißen?!

_________________
Die Lösung ist nicht siebzehn.
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Do 27.11.08 18:09 
user profile iconMitmischer 1703 hat folgendes geschrieben Zum zitierten Posting springen:

@ JayEff: Wieso if i mod 1000 = 0? Müsste das nicht if i mod 1000 = 1 heißen?!


Dann würde der 1., der 1001., 2001... Durchgang die Bedingung erfüllen. Wenn man das will... ;-) Ich würde auf mod = 0 prüfen.
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 27.11.08 22:31 
user profile iconfreak4fun hat folgendes geschrieben Zum zitierten Posting springen:
Für den Anfang: Eine kleine Beschreibung und ein jederzeit ansprechbares Programm. ;)


Was genau meinst du mit jederzeit ansprechbar ? Wann ist es das denn nicht ? Während des berechnens der Zahlen ?


user profile iconfreedy hat folgendes geschrieben Zum zitierten Posting springen:
Such im Forum mal nach QueryPerformanceCounter und QueryPerformanceFrequcency. Das wäre schon mal ein Anfang...


Danke werde ich versuchen :wink:

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 28.11.08 10:25 
user profile iconGericasS hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconfreak4fun hat folgendes geschrieben Zum zitierten Posting springen:
Für den Anfang: Eine kleine Beschreibung und ein jederzeit ansprechbares Programm. ;)


Was genau meinst du mit jederzeit ansprechbar ? Wann ist es das denn nicht ? Während des berechnens der Zahlen ?


user profile iconJayEff hat folgendes geschrieben Zum zitierten Posting springen:
Ebenfalls wäre ein Application.ProcessMessage alle, sagen wir, 1000 schleifendurchläufe damit die fortschrittsanzeige auch was anzeigt und das (Keine Rückmeldung) ausbleibt vielleicht angebracht. ( if i mod 1000 = 0 then Application.ProcessMessages; heißt die Zauberzeile :zustimm: )

Die Zauberzeile gehört in die Schleife, falls i deine Schleifenvariable ist :) Rufe Application.ProcessMessages nicht zu oft auf (alle 1000 mal sollte reichen), denn sonst verlangsamt das deinen Algorithmus - das ist allerdings bei einem Benchmarking Tool wohl nicht so schlimm, da es ja ohnehin darum geht eine weile zu brauchen.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.