Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.167 Beiträge
 
Delphi 12 Athens
 
#12

Re: dynamische Arrays vergrößern

  Alt 10. Jun 2009, 19:44
Delphi-Quellcode:
var
  a: Array of Integer;
  aLen, i, i2, i3: Integer;
  C, C2: LongWord;

begin
  C := GetTickCount;
  for i2 := 1 to 10000000 do begin
    i := Length(a);

    SetLength(a, i + 1);

    a[i] := 123456;
  End;
  C := GetTickCount - C;

  a := nil;
  aLen := 0;

  C2 := GetTickCount;
  for i2 := 1 to 10000000 do begin
    i := aLen;

    Inc(aLen);
    i3 := (aLen + $FF) and not $FF;
    if i3 <> Length(a) then SetLength(a, i3);

    a[i] := 123456;
  end;
  C2 := GetTickCount - C2;

  Application.MessageBox(PChar(Format('C = %d ms'#13#10'C2 = %d ms', [C, C2])), 'Test');
end;
Zitat:
---------------------------
Test
---------------------------
C = 1094 ms

C2 = 78 ms
---------------------------
OK
---------------------------
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat