Ignore:
Timestamp:
Oct 29, 2010, 7:49:29 AM (14 years ago)
Author:
george
Message:
  • Added: Partial generic set implementation.
  • Modified: TGStack, TGQueue and TGSet owns TGList instead of inherits.
  • Added: TList and TListPointer benchmark comparasion.
Location:
Generics/TemplateGenerics/Demo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Demo

    • Property svn:ignore
      •  

        old new  
        11lib
         2Demo.exe
  • Generics/TemplateGenerics/Demo/UMainForm.pas

    r74 r76  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ListInteger, ListString, DictionaryString, QueueInteger, ListChar;
     9  ComCtrls, ListInteger, ListString, DictionaryString, QueueInteger, ListChar,
     10  ListPointer, DateUtils, ListVariant;
    1011
    1112type
     
    1415
    1516  TMainForm = class(TForm)
     17    ButtonBenchmark: TButton;
    1618    ButtonCharList: TButton;
    1719    ButtonQueueInteger: TButton;
     
    2022    ButtonStringList: TButton;
    2123    MemoOutput: TMemo;
     24    procedure ButtonBenchmarkClick(Sender: TObject);
    2225    procedure ButtonCharListClick(Sender: TObject);
    2326    procedure ButtonDictionaryStringClick(Sender: TObject);
     
    2831    procedure FormDestroy(Sender: TObject);
    2932  private
    30     { private declarations }
    3133  public
    3234    procedure WriteLn(Text: string);
     
    8688    Enqueue(2);
    8789    Enqueue(3);
    88     WriteLn('Implode: ' + Implode(',', IntToStr));
     90    WriteLn('Implode: ' + List.Implode(',', IntToStr));
    8991    WriteLn('Enqueue: 4');
    9092    Enqueue(4);
    91     WriteLn('Implode: ' + Implode(',', IntToStr));
     93    WriteLn('Implode: ' + List.Implode(',', IntToStr));
    9294    WriteLn('Dequeue: ' + IntToStr(Dequeue));
    93     WriteLn('Implode: ' + Implode(',', IntToStr));
     95    WriteLn('Implode: ' + List.Implode(',', IntToStr));
    9496  finally
    9597    Free;
     
    158160end;
    159161
     162procedure TMainForm.ButtonBenchmarkClick(Sender: TObject);
     163var
     164  List: TListPointer;
     165  List2: TList;
     166  StartTime: TDateTime;
     167  I: Integer;
     168begin
     169  MemoOutput.Clear;
     170  try
     171    List := TListPointer.Create;
     172    WriteLn('TListPointer...');
     173    StartTime := Now;
     174    repeat
     175      List.Add(1);
     176    until (Now - StartTime) > OneSecond;
     177    WriteLn('Add: ' + IntToStr(List.Count) + ' ops/sec');
     178    List.Clear;
     179
     180    StartTime := Now;
     181    repeat
     182      List.Insert(0, 1);
     183    until (Now - StartTime) > OneSecond;
     184    WriteLn('Insert: ' + IntToStr(List.Count) + ' ops/sec');
     185    List.Clear;
     186
     187    for I := 0 to 1000000 do
     188      List.Add(1);
     189    StartTime := Now;
     190    I := 0;
     191    repeat
     192      List.Delete(0);
     193      Inc(I);
     194    until (Now - StartTime) > OneSecond;
     195    WriteLn('Delete: ' + IntToStr(I) + ' ops/sec');
     196    List.Clear;
     197
     198    for I := 0 to 1000000 do
     199      List.Add(1);
     200    StartTime := Now;
     201    I := 0;
     202    repeat
     203      List.Move(300000, 700000);
     204      Inc(I);
     205    until (Now - StartTime) > OneSecond;
     206    WriteLn('Move: ' + IntToStr(I) + ' ops/sec');
     207    List.Clear;
     208
     209  finally
     210    List.Free;
     211  end;
     212
     213  try
     214    List2 := TList.Create;
     215    WriteLn('Test TList...');
     216    StartTime := Now;
     217    repeat
     218      List2.Add(1);
     219    until (Now - StartTime) > OneSecond;
     220    WriteLn('Add: ' + IntToStr(List2.Count) + ' ops/sec');
     221    List2.Clear;
     222
     223    StartTime := Now;
     224    repeat
     225      List2.Insert(0, 1);
     226    until (Now - StartTime) > OneSecond;
     227    WriteLn('Insert: ' + IntToStr(List2.Count) + ' ops/sec');
     228    List2.Clear;
     229
     230    for I := 0 to 1000000 do
     231      List2.Add(1);
     232    StartTime := Now;
     233    I := 0;
     234    repeat
     235      List2.Delete(0);
     236      Inc(I);
     237    until (Now - StartTime) > OneSecond;
     238    WriteLn('Delete: ' + IntToStr(I) + ' ops/sec');
     239
     240      for I := 0 to 1000000 do
     241      List2.Add(1);
     242    StartTime := Now;
     243    I := 0;
     244    repeat
     245      List2.Move(300000, 700000);
     246      Inc(I);
     247    until (Now - StartTime) > OneSecond;
     248    WriteLn('Move: ' + IntToStr(I) + ' ops/sec');
     249
     250  finally
     251    List2.Free;
     252  end;
     253end;
     254
    160255function StrToStr(Value: string): string;
    161256begin
Note: See TracChangeset for help on using the changeset viewer.