Einzelnen Beitrag anzeigen

Iwo Asnet

Registriert seit: 11. Jun 2011
313 Beiträge
 
#12

AW: StringList oder dynamisches Array.

  Alt 9. Feb 2012, 17:07
Delphi-Quellcode:
program TestStringLists;

{$APPTYPE CONSOLE}

uses
  Windows, Classes, SysUtils;
Const
  R = 1000;

Var
  A : Array [0..10000] Of String;
  S : TStringList;
  
  Procedure ArrayProc;
  Var
    T : Cardinal;
    i : Integer;
    Procedure AppendProc;
    Var i : Integer;
    Begin
      for I := 0 to High(a) do A[i] := '123123123123';
    End;

    Procedure FetchProc;
    Var i : Integer; s: String;
    Begin
      for I := 0 to High(a) do s := A[i];
      if S='123then A[0] := '';
    End;

    Procedure InsertProc;
    Var i : Integer;
    Begin
      for I := 0 to High(A) do
        Move(A[0], A[1], High(A)*SizeOf(A[0]));
    End;

    Procedure DeleteProc;
    Var i : Integer;
    Begin
      for I := 0 to High(A) do
        Move(A[1], A[0], High(A)*SizeOf(A[0]));
    End;
  Begin
    T := GetTickCount;
    For i:=1 to R do AppendProc;
    Writeln('Array - Add : ',GetTickcount-t);
    T := GetTickCount;
    For i:=1 to R do FetchProc;
    Writeln('Array - Fetch : ',GetTickcount-t);
    T := GetTickCount;
    For i:=1 to R div 100 do Begin InsertProc; DeleteProc; End;
    Writeln('Array - Ins/Del : ',GetTickcount-t);
  End;
  Procedure StringListProc;
  Var
    T : Cardinal;
    i : Integer;
    Procedure AppendProc;
    Var i : Integer;
    Begin
      for I := 0 to High(a) do S.Add('123123123123');
    End;

    Procedure FetchProc;
    Var i : Integer; x: String;
    Begin
      for I := 0 to High(a) do x := S[i];
      if x='123then S[0] := '';
    End;

    Procedure InsertProc;
    Var i : Integer;
    Begin
      for i := 0 to High(A) do begin
        S.Insert(0,'1^23123123');
        s.Delete(0);
      end;
    End;

    Procedure DeleteProc;
    Var i : Integer;
    Begin
      for i := 0 to High(A) do
        S.Delete(0);
    End;
  Begin
    s:= TStringlist.Create;
    T := GetTickCount;
    For i:=1 to R do AppendProc;
    Writeln('StrLst - Add : ',GetTickcount-t);

    T := GetTickCount;
    For i:=1 to R do FetchProc;
    Writeln('StrLst - Fetch : ',GetTickcount-t);
    s.clear;
    AppendProc; // damit die Stringlist auch 10000 elemente zum Testen hat
    T := GetTickCount;
    For i:=1 to R div 100 do InsertProc;
    Writeln('StrLst - In/Del : ',GetTickcount-t);
   s.free;
 End;
begin
  ArrayProc;
  StringListProc;
  ReadLn;
end.

Geändert von Iwo Asnet ( 9. Feb 2012 um 17:13 Uhr)
  Mit Zitat antworten Zitat