Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#88

AW: Procedure vs Function, Vor- und Nachteile

  Alt 22. Apr 2018, 07:41
Kleiner Bench Verbesserungs-Vorschlag
Delphi-Quellcode:
const
  amount = 1000000;
  attempts = 50;
var
  x,y: cardinal;
// tickstart, tickfinish: cardinal;
  ticks: cardinal; // eine variable genügt
// allcounts: cardinal;
  s: String;
begin
  Randomize; // einmal reicht, oder?
  SetLength(s, Random(255)); // lieber nur ein random um ein ein präziseres ergebniss zu erhalten, man will ja nicht random benchen
// allcounts := 0;
  for x := 1 to attempts do
  begin
    y := 1;
    ticks := GetTickCount;
// tickstart := GetTickCount;
    while y <= amount do
    begin
// Randomize;
// SetLength(s, Random(255));
      //entw Foo(s);
      //oder FooC(s);
      //oder FooV(s);
      inc(y);
    end;
// tickfinish := GetTickCount;
// allcounts := allcounts + tickfinish - tickstart; // 0 + tickdifferenz
    ticks := GetTickCount - ticks;
  end;
// showmessage(inttostr((allcounts div attempts)));
  showmessage(inttostr((ticks div attempts)));
end;
Ich habe es noch nicht getestet aber so erscheint es mir logischer
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat