Ignore:
Timestamp:
Jan 5, 2018, 10:24:36 PM (7 years ago)
Author:
chronos
Message:
  • Modified: New native generics classes working under FPC 3.0 transformed from TemplateGenerics package.
Location:
Generics/NativeGenerics/Demo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics/NativeGenerics/Demo

    • Property svn:ignore
      •  

        old new  
        33Demo.exe
        44heaptrclog.trc
         5Demo
  • Generics/NativeGenerics/Demo/UMainForm.pas

    r481 r496  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, GenericList, GenericDictionary, GenericQueue, GenericStream,
    10   DateUtils, GenericString, GenericTree;
     9  ComCtrls, DateUtils, GenericList, GenericMatrix, GenericQueue, fgl,
     10  GenericDictionary, SpecializedStream, SpecializedList;
    1111
    1212type
     
    1515
    1616  TMainForm = class(TForm)
    17     TreeButton: TButton;
    18     StreamByteButton: TButton;
     17    ButtonStreamByte: TButton;
    1918    ButtonBenchmarkDictionary: TButton;
    2019    ButtonBenchmarkListPointer: TButton;
    21     ListObjectButton: TButton;
     20    ButtonListObject: TButton;
    2221    ButtonBenchmarkListString: TButton;
    23     CharListButton: TButton;
    24     MatrixIntegerButton: TButton;
    25     QueueIntegerButton: TButton;
    26     DictionaryStringButton: TButton;
    27     IntegerListButton: TButton;
    28     StringListButton: TButton;
     22    ButtonCharList: TButton;
     23    ButtonMatrixInteger: TButton;
     24    ButtonQueueInteger: TButton;
     25    ButtonDictionaryString: TButton;
     26    ButtonIntegerList: TButton;
     27    ButtonStringList: TButton;
    2928    Label1: TLabel;
    3029    LabelTestName: TLabel;
     
    3332    procedure ButtonBenchmarkListPointerClick(Sender: TObject);
    3433    procedure ButtonBenchmarkListStringClick(Sender: TObject);
    35     procedure CharListButtonClick(Sender: TObject);
    36     procedure DictionaryStringButtonClick(Sender: TObject);
    37     procedure IntegerListButtonClick(Sender: TObject);
    38     procedure MatrixIntegerButtonClick(Sender: TObject);
    39     procedure ListObjectButtonClick(Sender: TObject);
    40     procedure QueueIntegerButtonClick(Sender: TObject);
    41     procedure StreamByteButtonClick(Sender: TObject);
    42     procedure StringListButtonClick(Sender: TObject);
     34    procedure ButtonCharListClick(Sender: TObject);
     35    procedure ButtonDictionaryStringClick(Sender: TObject);
     36    procedure ButtonIntegerListClick(Sender: TObject);
     37    procedure ButtonMatrixIntegerClick(Sender: TObject);
     38    procedure ButtonListObjectClick(Sender: TObject);
     39    procedure ButtonQueueIntegerClick(Sender: TObject);
     40    procedure ButtonStringListClick(Sender: TObject);
     41    procedure ButtonStreamByteClick(Sender: TObject);
    4342    procedure FormCreate(Sender: TObject);
    4443    procedure FormDestroy(Sender: TObject);
    45     procedure TreeButtonClick(Sender: TObject);
    46   private
    4744  public
    4845    MeasureDuration: TDateTime;
     46    Bitmap: TBitmap;
    4947    procedure UpdateButtonState(Enabled: Boolean);
    5048    procedure WriteOutput(Text1: string = ''; Text2: string = '');
     
    6563end;
    6664
    67 procedure TMainForm.IntegerListButtonClick(Sender: TObject);
     65procedure TMainForm.ButtonIntegerListClick(Sender: TObject);
    6866var
    6967  List: TGList<Integer>;
     
    7270begin
    7371  ListViewOutput.Clear;
    74   LabelTestName.Caption := 'TGList<Integer> test';
     72  LabelTestName.Caption := 'TListInteger test';
    7573  List := TGList<Integer>.Create;
    7674  List2 := TGList<Integer>.Create;
     
    8785    WriteOutput('First', IntToStr(First));
    8886    WriteOutput('Last', IntToStr(Last));
     87    WriteOutput('IndexOf(7)', IntToStr(IndexOf(7)));
    8988    MoveItems(3, 2, 3);
    9089    WriteOutput('MoveItems(3, 2, 3)', Implode(',', IntToStr));
     
    107106end;
    108107
    109 procedure TMainForm.MatrixIntegerButtonClick(Sender: TObject);
    110 //var
    111 //  Matrix: TGMatrix<Integer, Integer, Integer>;
    112 begin
    113   (*  ListViewOutput.Clear;
    114   LabelTestName.Caption := 'TGMatrix<Integer> test';
    115   Matrix := TGMatrix<Integer, Integer, Integer>.Create;
     108procedure TMainForm.ButtonMatrixIntegerClick(Sender: TObject);
     109var
     110  Matrix: TGMatrix<Integer>;
     111  I: Integer;
     112begin
     113  ListViewOutput.Clear;
     114  LabelTestName.Caption := 'TMatrixInteger test';
     115  Matrix := TGMatrix<Integer>.Create;
    116116  with Matrix do try
    117117    Count := CreateIndex(2, 2);
     
    127127  finally
    128128    Free;
    129   end; *)
    130 end;
    131 
    132 function ObjectToStr(Obj: TObject): string;
    133 begin
    134   Result := Obj.ClassName;
    135 end;
    136 
    137 procedure TMainForm.ListObjectButtonClick(Sender: TObject);
    138 var
    139   List: TGObjectList<TObject>;
    140   I: Integer;
    141 begin
    142   ListViewOutput.Clear;
    143   LabelTestName.Caption := 'TObjectList<TObject> test';
    144   List := TGObjectList<TObject>.Create;
    145   with List do try
    146     AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create]);
    147     WriteOutput('AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create])', Implode(',', ObjectToStr));
    148     Clear;
    149     WriteOutput('Clear', Implode(',', ObjectToStr));
    150     for I := 0 to 10 do Add(TObject.Create);
    151     WriteOutput('for I := 0 to 10 do Add(TObject.Create)', Implode(',', ObjectToStr));
    152     WriteOutput('Count', IntToStr(Count));
    153     Reverse;
    154     WriteOutput('Reverse', Implode(',', ObjectToStr));
    155     MoveItems(3, 2, 3);
    156     WriteOutput('MoveItems(3, 2, 3)', Implode(',', ObjectToStr));
    157   finally
    158     Free;
    159   end;
    160 end;
    161 
    162 procedure TMainForm.QueueIntegerButtonClick(Sender: TObject);
    163 var
    164   Queue: TGQueue<Integer>;
    165 begin
    166   ListViewOutput.Clear;
    167   LabelTestName.Caption := 'TGQueue<Integer> test';
    168   Queue := TGQueue<Integer>.Create;
    169   with Queue do try
    170     Enqueue(1);
    171     Enqueue(2);
    172     Enqueue(3);
    173     WriteOutput('Enqueue(1),Enqueue(2),Enqueue(3) ', List.Implode(',', IntToStr));
    174     Enqueue(4);
    175     WriteOutput('Enqueue(4)', List.Implode(',', IntToStr));
    176     WriteOutput('Dequeued item', IntToStr(Dequeue));
    177     WriteOutput('Dequeue', List.Implode(',', IntToStr));
    178   finally
    179     Free;
    180   end;
    181 end;
    182 
    183 procedure TMainForm.StreamByteButtonClick(Sender: TObject);
    184 var
    185   Stream: TGStream<Byte>;
     129  end;
     130end;
     131
     132procedure TMainForm.ButtonStreamByteClick(Sender: TObject);
     133var
     134  Stream: TMemoryStreamByte;
    186135  I: Integer;
    187136  ByteArray: array of Byte;
     
    189138begin
    190139  ListViewOutput.Clear;
    191   LabelTestName.Caption := 'TGStream<Byte> test';
    192   Stream := TGStream<Byte>.Create;
     140  LabelTestName.Caption := 'TStreamByte test';
     141  Stream := TMemoryStreamByte.Create;
    193142  with Stream do try
    194143    WriteOutput('Size := ', IntToStr(Stream.Size));
     
    218167end;
    219168
    220 function StringPairToStr(Pair: TGPair<String, String>): string;
     169function ObjectToStr(Obj: TObject): string;
     170begin
     171  Result := Obj.ClassName;
     172end;
     173
     174procedure TMainForm.ButtonListObjectClick(Sender: TObject);
     175var
     176  List: TGListObject<TObject>;
     177  I: Integer;
     178begin
     179  ListViewOutput.Clear;
     180  LabelTestName.Caption := 'TListObject test';
     181  List := TGListObject<TObject>.Create;
     182  with List do try
     183    AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create]);
     184    WriteOutput('AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create])', Implode(',', ObjectToStr));
     185    Clear;
     186    WriteOutput('Clear', Implode(',', ObjectToStr));
     187    for I := 0 to 10 do Add(TObject.Create);
     188    WriteOutput('for I := 0 to 10 do Add(TObject.Create)', Implode(',', ObjectToStr));
     189    WriteOutput('Count', IntToStr(Count));
     190    Reverse;
     191    WriteOutput('Reverse', Implode(',', ObjectToStr));
     192    MoveItems(3, 2, 3);
     193    WriteOutput('MoveItems(3, 2, 3)', Implode(',', ObjectToStr));
     194  finally
     195    Free;
     196  end;
     197end;
     198
     199procedure TMainForm.ButtonQueueIntegerClick(Sender: TObject);
     200var
     201  Queue: TGQueue<Integer>;
     202  I: Integer;
     203begin
     204  ListViewOutput.Clear;
     205  LabelTestName.Caption := 'TQueueInteger test';
     206  Queue := TGQueue<Integer>.Create;
     207  with Queue do try
     208    Enqueue(1);
     209    Enqueue(2);
     210    Enqueue(3);
     211    WriteOutput('Enqueue(1),Enqueue(2),Enqueue(3) ', List.Implode(',', IntToStr));
     212    Enqueue(4);
     213    WriteOutput('Enqueue(4)', List.Implode(',', IntToStr));
     214    WriteOutput('Dequeued item', IntToStr(Dequeue));
     215    WriteOutput('Dequeue', List.Implode(',', IntToStr));
     216  finally
     217    Free;
     218  end;
     219end;
     220
     221function StringPairToStr(Pair: TGPair<string,string>): string;
    221222begin
    222223  Result := Pair.Key + ':' + Pair.Value;
    223224end;
    224225
    225 procedure TMainForm.DictionaryStringButtonClick(Sender: TObject);
    226 //type
    227 //  TPairStringString = TGPair<string, string>;
     226procedure TMainForm.ButtonDictionaryStringClick(Sender: TObject);
    228227var
    229228  Dictionary: TGDictionary<string, string>;
    230229begin
    231230  ListViewOutput.Clear;
    232   LabelTestName.Caption := 'TGDictionary<string, string> test';
     231  LabelTestName.Caption := 'TDictionaryString test';
    233232  Dictionary := TGDictionary<string, string>.Create;
    234233  with Dictionary do try
     
    241240    Values['Key2'] := 'None';
    242241    WriteOutput('Values[Key2]', Values['Key2']);
    243     WriteOutput('Index of Key0', IntToStr(SearchKey('Key0')));
     242    WriteOutput('Values[Key0]', Values['Key0']);
    244243    WriteOutput('Keys[2]', Keys[2]);
    245244  finally
     
    253252end;
    254253
    255 procedure TMainForm.CharListButtonClick(Sender: TObject);
    256 var
    257   List: TGString<Char>;
    258   List2: TGString<Char>;
    259 begin
    260   ListViewOutput.Clear;
    261   LabelTestName.Caption := 'TGString<Char> test';
    262   List := TGString<Char>.Create;
    263   List2 := TGString<Char>.Create;
     254procedure TMainForm.ButtonCharListClick(Sender: TObject);
     255var
     256  List: TListChar;
     257  List2: TListChar;
     258begin
     259  ListViewOutput.Clear;
     260  LabelTestName.Caption := 'TListChar test';
     261  List := TListChar.Create;
     262  List2 := TListChar.Create;
    264263  with List do try
    265264    AddArray([' ', ' ', 'A', 'b', 'c', 'd', ' ']);
     
    287286procedure TMainForm.ButtonBenchmarkListStringClick(Sender: TObject);
    288287var
    289   List: TGList<String>;
     288  List: TGList<string>;
    290289  List2: TStringList;
    291290  StartTime: TDateTime;
     
    295294  SampleCount: Integer = 100000;
    296295begin
    297   LabelTestName.Caption := 'Generic specialized TGStringList<string> vs. classic non-generic TStringList benchmark';
     296  LabelTestName.Caption := 'Generic specialized TListString vs. classic non-generic TStringList benchmark';
    298297  ListViewOutput.Clear;
    299298  try
    300299    UpdateButtonState(False);
    301     List := TGList<String>.Create;
     300    List := TGList<string>.Create;
    302301    List2 := TStringList.Create;
    303302
     
    306305      List.Add(SampleText);
    307306    until (Now - StartTime) > MeasureDuration;
    308     WriteOutput('TListString.Add', IntToStr(List.Count) + ' ops');
     307    WriteOutput('TGList<String>.Add', IntToStr(List.Count) + ' ops');
    309308    List.Clear;
    310309    Application.ProcessMessages;
     
    322321      List.Insert(0, SampleText);
    323322    until (Now - StartTime) > MeasureDuration;
    324     WriteOutput('TListString.Insert', IntToStr(List.Count) + ' ops');
     323    WriteOutput('TGList<String>.Insert', IntToStr(List.Count) + ' ops');
    325324    List.Clear;
    326325    Application.ProcessMessages;
     
    342341      Inc(I);
    343342    until (Now - StartTime) > MeasureDuration;
    344     WriteOutput('TListString.Delete', IntToStr(I) + ' ops');
     343    WriteOutput('TGList<String>.Delete', IntToStr(I) + ' ops');
    345344    List.Clear;
    346345    Application.ProcessMessages;
     
    365364      Inc(I);
    366365    until (Now - StartTime) > MeasureDuration;
    367     WriteOutput('TListString.Move', IntToStr(I) + ' ops');
     366    WriteOutput('TGList<String>.Move', IntToStr(I) + ' ops');
    368367    List.Clear;
    369368    Application.ProcessMessages;
     
    388387      Inc(I);
    389388    until (Now - StartTime) > MeasureDuration;
    390     WriteOutput('TListString.Exchange', IntToStr(I) + ' ops');
     389    WriteOutput('TGList<String>.Exchange', IntToStr(I) + ' ops');
    391390    List.Clear;
    392391    Application.ProcessMessages;
     
    411410      Inc(I);
    412411    until (Now - StartTime) > MeasureDuration;
    413     WriteOutput('TListString.IndexOf', IntToStr(I) + ' ops');
     412    WriteOutput('TGList<String>.IndexOf', IntToStr(I) + ' ops');
    414413    List.Clear;
    415414    Application.ProcessMessages;
     
    434433
    435434procedure TMainForm.ButtonBenchmarkDictionaryClick(Sender: TObject);
    436 //type
    437 //  TPairStringString = TGPair<String, String>;
    438 var
    439   Dictionary: TGDictionary<string, string>;
     435var
     436  Dictionary: TGDictionary<string,string>;
    440437  Dictionary2: TStringList;
    441438  StartTime: TDateTime;
     
    443440  R: string;
    444441begin
    445   LabelTestName.Caption := 'Generic specialized TGDictionary<string,string> vs. classic non-generic TStringList benchmark';
     442  LabelTestName.Caption := 'Generic specialized TDictionaryStringString vs. classic non-generic TStringList benchmark';
    446443  ListViewOutput.Clear;
    447444  try
    448445    UpdateButtonState(False);
    449     Dictionary := TGDictionary<string, string>.Create;
     446    Dictionary := TGDictionary<string,string>.Create;
    450447    Dictionary2 := TStringList.Create;
    451448    Dictionary2.NameValueSeparator := '|';
     
    457454      I := I + 1;
    458455    until (Now - StartTime) > MeasureDuration;
    459     WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.List.Count) + ' ops');
     456    WriteOutput('TGDictionary<string,string>.Add', IntToStr(Dictionary.Count) + ' ops');
    460457    Application.ProcessMessages;
    461458
     
    472469    StartTime := Now;
    473470    repeat
    474       R := Dictionary.Values[IntToStr(I mod Dictionary.List.Count)];
     471      R := Dictionary.Values[IntToStr(I mod Dictionary.Count)];
    475472      I := I + 1;
    476473    until (Now - StartTime) > MeasureDuration;
    477     WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops');
     474    WriteOutput('TGDictionary<string,string>.Values', IntToStr(I) + ' ops');
    478475    Application.ProcessMessages;
    479476
     
    490487    StartTime := Now;
    491488    repeat
    492       R := Dictionary.Keys[I mod Dictionary.List.Count];
     489      R := Dictionary.Keys[I mod Dictionary.Count];
    493490      I := I + 1;
    494491    until (Now - StartTime) > MeasureDuration;
    495     WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops');
     492    WriteOutput('TGDictionary<string,string>.Keys', IntToStr(I) + ' ops');
    496493    Application.ProcessMessages;
    497494
     
    508505    StartTime := Now;
    509506    repeat
    510       R := Dictionary.List.Items[I mod Dictionary.List.Count].Value;
     507      R := Dictionary.List.Items[I mod Dictionary.Count].Value;
    511508      I := I + 1;
    512509    until (Now - StartTime) > MeasureDuration;
    513     WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops');
     510    WriteOutput('TGDictionary<string,string>.Items', IntToStr(I) + ' ops');
    514511    Application.ProcessMessages;
    515512
     
    534531  List: TGList<Pointer>;
    535532  List2: TFPList;
     533  List3: TFPGList<Pointer>;
     534  S: TList;
    536535  StartTime: TDateTime;
    537536  I: Integer;
     537  K: Integer;
    538538const
    539539  SampleCount: Integer = 100000;
    540540begin
    541   LabelTestName.Caption := 'Generic specialized TGObjectList<Object> vs. classic non-generic TFPList benchmark';
     541  LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TFPList benchmark';
    542542  ListViewOutput.Clear;
    543543  try
     
    545545    List := TGList<Pointer>.Create;
    546546    List2 := TFPList.Create;
    547 
    548     WriteOutput('TListPointer.InstanceSize', IntToStr(TGList<Pointer>.InstanceSize) + ' bytes');
     547    List3 := TFPGList<Pointer>.Create;
     548
     549    WriteOutput('TGList<Pointer>.InstanceSize', IntToStr(TGList<Pointer>.InstanceSize) + ' bytes');
    549550    WriteOutput('TFPList.InstanceSize', IntToStr(TFPList.InstanceSize) + ' bytes');
     551    WriteOutput('TFPGList<Pointer>.InstanceSize', IntToStr(TFPGList<Pointer>.InstanceSize) + ' bytes');
    550552
    551553    StartTime := Now;
     
    553555      List.Add(Pointer(1));
    554556    until (Now - StartTime) > MeasureDuration;
    555     WriteOutput('TListPointer.Add', IntToStr(List.Count) + ' ops');
     557    WriteOutput('TGList<Pointer>.Add', IntToStr(List.Count) + ' ops');
    556558    List.Clear;
    557559    Application.ProcessMessages;
     
    567569    StartTime := Now;
    568570    repeat
     571      List3.Add(Pointer(1));
     572    until (Now - StartTime) > MeasureDuration;
     573    WriteOutput('TFPGList<Pointer>.Add', IntToStr(List3.Count) + ' ops');
     574    List3.Clear;
     575    Application.ProcessMessages;
     576
     577    StartTime := Now;
     578    repeat
    569579      List.Insert(0, Pointer(1));
    570580    until (Now - StartTime) > MeasureDuration;
    571     WriteOutput('TListPointer.Insert', IntToStr(List.Count) + ' ops');
     581    WriteOutput('TGList<Pointer>.Insert', IntToStr(List.Count) + ' ops');
    572582    List.Clear;
    573583    Application.ProcessMessages;
     
    581591    Application.ProcessMessages;
    582592
     593    StartTime := Now;
     594    repeat
     595      List3.Insert(0, Pointer(1));
     596    until (Now - StartTime) > MeasureDuration;
     597    WriteOutput('TFPGList<Pointer>.Insert', IntToStr(List3.Count) + ' ops');
     598    List3.Clear;
     599    Application.ProcessMessages;
     600
    583601    for I := 0 to SampleCount - 1 do
    584602      List.Add(Pointer(1));
     
    589607      Inc(I);
    590608    until (Now - StartTime) > MeasureDuration;
    591     WriteOutput('TListPointer.Delete', IntToStr(I) + ' ops');
     609    WriteOutput('TGList<Pointer>.Delete', IntToStr(I) + ' ops');
    592610    List.Clear;
    593611    Application.ProcessMessages;
     
    605623
    606624    for I := 0 to SampleCount - 1 do
     625      List3.Add(Pointer(1));
     626    StartTime := Now;
     627    I := 0;
     628    repeat
     629      List3.Delete(0);
     630      Inc(I);
     631    until (Now - StartTime) > MeasureDuration;
     632    WriteOutput('TFPGList<Pointer>.Delete', IntToStr(I) + ' ops');
     633    Application.ProcessMessages;
     634
     635    for I := 0 to SampleCount - 1 do
    607636      List.Add(Pointer(1));
    608637    StartTime := Now;
     
    612641      Inc(I);
    613642    until (Now - StartTime) > MeasureDuration;
    614     WriteOutput('TListPointer.Move', IntToStr(I) + ' ops');
    615     List.Clear;
    616     Application.ProcessMessages;
    617 
    618     for I := 0 to SampleCount - 1 do
    619     List2.Add(Pointer(1));
     643    WriteOutput('TGList<Pointer>.Move', IntToStr(I) + ' ops');
     644    List.Clear;
     645    Application.ProcessMessages;
     646
     647    for I := 0 to SampleCount - 1 do
     648      List2.Add(Pointer(1));
    620649    StartTime := Now;
    621650    I := 0;
     
    628657
    629658    for I := 0 to SampleCount - 1 do
     659      List3.Add(Pointer(1));
     660    StartTime := Now;
     661    I := 0;
     662    repeat
     663      List3.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     664      Inc(I);
     665    until (Now - StartTime) > MeasureDuration;
     666    WriteOutput('TFPGList<Pointer>.Move', IntToStr(I) + ' ops');
     667    Application.ProcessMessages;
     668
     669    for I := 0 to SampleCount - 1 do
    630670      List.Add(Pointer(1));
    631671    StartTime := Now;
     
    635675      Inc(I);
    636676    until (Now - StartTime) > MeasureDuration;
    637     WriteOutput('TListPointer.Exchange', IntToStr(I) + ' ops');
    638     List.Clear;
    639     Application.ProcessMessages;
    640 
    641     for I := 0 to SampleCount - 1 do
    642     List2.Add(Pointer(1));
     677    WriteOutput('TGList<Pointer>.Exchange', IntToStr(I) + ' ops');
     678    Application.ProcessMessages;
     679
     680    for I := 0 to SampleCount - 1 do
     681      List2.Add(Pointer(1));
    643682    StartTime := Now;
    644683    I := 0;
     
    651690
    652691    for I := 0 to SampleCount - 1 do
     692      List3.Add(Pointer(1));
     693    StartTime := Now;
     694    I := 0;
     695    repeat
     696      List3.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     697      Inc(I);
     698    until (Now - StartTime) > MeasureDuration;
     699    WriteOutput('TFPGList<Pointer>.Exchange', IntToStr(I) + ' ops');
     700    Application.ProcessMessages;
     701
     702    for I := 0 to SampleCount - 1 do
     703      List.Add(Pointer(I));
     704    StartTime := Now;
     705    I := 0;
     706    repeat
     707      K := List.IndexOf(Pointer(I mod List.Count));
     708      Inc(I);
     709    until (Now - StartTime) > MeasureDuration;
     710    WriteOutput('TGList<Pointer>.IndexOf', IntToStr(I) + ' ops');
     711    List.Clear;
     712    Application.ProcessMessages;
     713
     714    for I := 0 to SampleCount - 1 do
     715      List2.Add(Pointer(I));
     716    StartTime := Now;
     717    I := 0;
     718    repeat
     719      K := List2.IndexOf(Pointer(I mod List2.Count));
     720      Inc(I);
     721    until (Now - StartTime) > MeasureDuration;
     722    WriteOutput('TFPList.IndexOf', IntToStr(I) + ' ops');
     723    Application.ProcessMessages;
     724
     725    for I := 0 to SampleCount - 1 do
     726      List3.Add(Pointer(I));
     727    StartTime := Now;
     728    I := 0;
     729    repeat
     730      K := List3.IndexOf(Pointer(I mod List3.Count));
     731      Inc(I);
     732    until (Now - StartTime) > MeasureDuration;
     733    WriteOutput('TFPGList<Pointer>.IndexOf', IntToStr(I) + ' ops');
     734    Application.ProcessMessages;
     735
     736    for I := 0 to SampleCount - 1 do
    653737      List.Add(Pointer(1));
    654738    StartTime := Now;
    655739    I := 0;
    656740    repeat
    657       List.IndexOf(Pointer(I mod List.Count));
    658       Inc(I);
    659     until (Now - StartTime) > MeasureDuration;
    660     WriteOutput('TListPointer.IndexOf', IntToStr(I) + ' ops');
    661     List.Clear;
    662     Application.ProcessMessages;
    663 
    664     for I := 0 to SampleCount - 1 do
    665     List2.Add(Pointer(1));
    666     StartTime := Now;
    667     I := 0;
    668     repeat
    669       List2.IndexOf(Pointer(I mod List2.Count));
    670       Inc(I);
    671     until (Now - StartTime) > MeasureDuration;
    672     WriteOutput('TFPList.IndexOf', IntToStr(I) + ' ops');
     741      List[I mod List.Count] := Pointer(1);
     742      Inc(I);
     743    until (Now - StartTime) > MeasureDuration;
     744    WriteOutput('TGList<Pointer>[I] write', IntToStr(I) + ' ops');
     745    List.Clear;
     746    Application.ProcessMessages;
     747
     748    for I := 0 to SampleCount - 1 do
     749      List2.Add(Pointer(1));
     750    StartTime := Now;
     751    I := 0;
     752    repeat
     753      List2[I mod List2.Count] := Pointer(1);
     754      Inc(I);
     755    until (Now - StartTime) > MeasureDuration;
     756    WriteOutput('TFPList[I] write', IntToStr(I) + ' ops');
     757    Application.ProcessMessages;
     758
     759    for I := 0 to SampleCount - 1 do
     760      List3.Add(Pointer(1));
     761    StartTime := Now;
     762    I := 0;
     763    repeat
     764      List3[I mod List3.Count] := Pointer(1);
     765      Inc(I);
     766    until (Now - StartTime) > MeasureDuration;
     767    WriteOutput('TFPGList<Pointer>[I] write', IntToStr(I) + ' ops');
    673768    Application.ProcessMessages;
    674769
     
    678773    I := 0;
    679774    repeat
    680       List[I mod List.Count] := Pointer(1);
    681       Inc(I);
    682     until (Now - StartTime) > MeasureDuration;
    683     WriteOutput('TListPointer[I] write', IntToStr(I) + ' ops');
    684     List.Clear;
    685     Application.ProcessMessages;
    686 
    687     for I := 0 to SampleCount - 1 do
    688     List2.Add(Pointer(1));
    689     StartTime := Now;
    690     I := 0;
    691     repeat
    692       List2[I mod List2.Count] := Pointer(1);
    693       Inc(I);
    694     until (Now - StartTime) > MeasureDuration;
    695     WriteOutput('TFPList[I] write', IntToStr(I) + ' ops');
    696     Application.ProcessMessages;
    697 
    698     for I := 0 to SampleCount - 1 do
    699       List.Add(Pointer(1));
    700     StartTime := Now;
    701     I := 0;
    702     repeat
    703775      List[I mod List.Count];
    704776      Inc(I);
    705777    until (Now - StartTime) > MeasureDuration;
    706     WriteOutput('TListPointer[I] read', IntToStr(I) + ' ops');
    707     List.Clear;
    708     Application.ProcessMessages;
    709 
    710     for I := 0 to SampleCount - 1 do
    711     List2.Add(Pointer(1));
     778    WriteOutput('TGList<Pointer>[I] read', IntToStr(I) + ' ops');
     779    List.Clear;
     780    Application.ProcessMessages;
     781
     782    for I := 0 to SampleCount - 1 do
     783      List2.Add(Pointer(1));
    712784    StartTime := Now;
    713785    I := 0;
     
    718790    WriteOutput('TFPList[I] read', IntToStr(I) + ' ops');
    719791    Application.ProcessMessages;
     792
     793    for I := 0 to SampleCount - 1 do
     794      List3.Add(Pointer(1));
     795    StartTime := Now;
     796    I := 0;
     797    repeat
     798      List3[I mod List3.Count];
     799      Inc(I);
     800    until (Now - StartTime) > MeasureDuration;
     801    WriteOutput('TFPGList<Pointer>[I] read', IntToStr(I) + ' ops');
     802    Application.ProcessMessages;
     803
    720804  finally
    721805    UpdateButtonState(True);
    722806    List.Free;
    723807    List2.Free;
     808    List3.Free;
    724809  end;
    725810end;
     
    730815end;
    731816
    732 procedure TMainForm.StringListButtonClick(Sender: TObject);
    733 var
    734   List: TGList<String>;
    735 begin
    736   ListViewOutput.Clear;
    737   WriteOutput('TGList<string> test');
    738   List := TGList<String>.Create;
     817procedure TMainForm.ButtonStringListClick(Sender: TObject);
     818var
     819  List: TGList<string>;
     820begin
     821  ListViewOutput.Clear;
     822  WriteOutput('TListString test');
     823  List := TGList<string>.Create;
    739824  with List do try
    740825    AddArray(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']);
     
    761846end;
    762847
    763 procedure TMainForm.TreeButtonClick(Sender: TObject);
    764 var
    765   //Tree: TGTree<string>;
    766   //Tree2: TGTree<string>;
    767   I: Integer;
    768 begin
    769  (* ListViewOutput.Clear;
    770   LabelTestName.Caption := 'TGTree<string> test';
    771   Tree := TGTree<string>.Create;
    772   Tree2 := TGTree<string>.Create;
    773   with Tree do try
    774     Tree.TopItem.Add('test');
    775     AddArray([10, 20, 30, 40]);
    776     WriteOutput('AddArray([10, 20, 30, 40])', Implode(',', IntToStr));
    777     Clear;
    778     WriteOutput('Clear', Implode(',', IntToStr));
    779     for I := 0 to 10 do Add(I);
    780     WriteOutput('for I := 0 to 10 do Add(I)', Implode(',', IntToStr));
    781     WriteOutput('Count', IntToStr(Count));
    782     Reverse;
    783     WriteOutput('Reverse', Implode(',', IntToStr));
    784     WriteOutput('First', IntToStr(First));
    785     WriteOutput('Last', IntToStr(Last));
    786     MoveItems(3, 2, 3);
    787     WriteOutput('MoveItems(3, 2, 3)', Implode(',', IntToStr));
    788     Insert(5, 11);
    789     WriteOutput('Insert(5, 11)', Implode(',', IntToStr));
    790     DeleteItems(0, 10);
    791     WriteOutput('Delete(0, 10)', Implode(',', IntToStr));
    792     List2.SetArray([1, 0]);
    793     WriteOutput('EqualTo([6, 11])', BoolToStr(EqualTo(List2)));
    794     List2.SetArray([2, 0]);
    795     WriteOutput('EqualTo([7, 11])', BoolToStr(EqualTo(List2)));
    796     InsertCount(0, 3);
    797     WriteOutput('InsertCount(0, 3)', Implode(',', IntToStr));
    798     Fill(0, 3, 9);
    799     WriteOutput('Fill(0, 3, 9)', Implode(',', IntToStr));
    800   finally
    801     Free;
    802     Tree2.Free;
    803   end;   *)
    804 end;
    805 
    806848procedure TMainForm.UpdateButtonState(Enabled: Boolean);
    807849begin
    808850  ButtonBenchmarkDictionary.Enabled := Enabled;
    809851  ButtonBenchmarkListString.Enabled := Enabled;
    810   CharListButton.Enabled := Enabled;
    811   DictionaryStringButton.Enabled := Enabled;
    812   IntegerListButton.Enabled := Enabled;
    813   ListObjectButton.Enabled := Enabled;
    814   MatrixIntegerButton.Enabled := Enabled;
    815   QueueIntegerButton.Enabled := Enabled;
    816   StringListButton.Enabled := Enabled;
     852  ButtonCharList.Enabled := Enabled;
     853  ButtonDictionaryString.Enabled := Enabled;
     854  ButtonIntegerList.Enabled := Enabled;
     855  ButtonListObject.Enabled := Enabled;
     856  ButtonMatrixInteger.Enabled := Enabled;
     857  ButtonQueueInteger.Enabled := Enabled;
     858  ButtonStringList.Enabled := Enabled;
    817859end;
    818860
Note: See TracChangeset for help on using the changeset viewer.