Changeset 111 for Generics


Ignore:
Timestamp:
Jan 3, 2011, 8:23:44 AM (14 years ago)
Author:
george
Message:
  • Added: TListString benchmark.
Location:
Generics/TemplateGenerics/Demo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Demo/Demo.lpi

    r110 r111  
    3838      </Item2>
    3939    </RequiredPackages>
    40     <Units Count="59">
     40    <Units Count="62">
    4141      <Unit0>
    4242        <Filename Value="Demo.lpr"/>
     
    5555        <ResourceBaseClass Value="Form"/>
    5656        <UnitName Value="UMainForm"/>
    57         <IsVisibleTab Value="True"/>
    5857        <EditorIndex Value="0"/>
    5958        <WindowIndex Value="0"/>
    60         <TopLine Value="404"/>
    61         <CursorPos X="49" Y="419"/>
     59        <TopLine Value="232"/>
     60        <CursorPos X="19" Y="237"/>
    6261        <UsageCount Value="233"/>
    6362        <Bookmarks Count="1">
    64           <Item0 X="65" Y="221" ID="2"/>
     63          <Item0 X="65" Y="224" ID="2"/>
    6564        </Bookmarks>
    6665        <Loaded Value="True"/>
     
    7776      </Unit2>
    7877      <Unit3>
    79         <Filename Value="../Specialized/specializedlist.pas"/>
     78        <Filename Value="../Specialized/SpecializedList.pas"/>
    8079        <UnitName Value="SpecializedList"/>
     80        <EditorIndex Value="2"/>
    8181        <WindowIndex Value="0"/>
    8282        <TopLine Value="3"/>
    8383        <CursorPos X="43" Y="13"/>
    84         <UsageCount Value="4"/>
     84        <UsageCount Value="10"/>
     85        <Loaded Value="True"/>
    8586      </Unit3>
    8687      <Unit4>
     
    311312      <Unit32>
    312313        <Filename Value="../Generic/GenericList.inc"/>
    313         <EditorIndex Value="2"/>
    314         <WindowIndex Value="0"/>
    315         <TopLine Value="170"/>
    316         <CursorPos X="82" Y="183"/>
     314        <EditorIndex Value="6"/>
     315        <WindowIndex Value="0"/>
     316        <TopLine Value="462"/>
     317        <CursorPos X="30" Y="470"/>
    317318        <UsageCount Value="107"/>
    318319        <Loaded Value="True"/>
     
    417418      <Unit46>
    418419        <Filename Value="../Generic/GenericMatrix.inc"/>
    419         <EditorIndex Value="3"/>
     420        <EditorIndex Value="7"/>
    420421        <WindowIndex Value="0"/>
    421422        <TopLine Value="311"/>
     
    493494        <Filename Value="../Specialized/SpecializedMatrix.pas"/>
    494495        <UnitName Value="SpecializedMatrix"/>
    495         <EditorIndex Value="4"/>
     496        <EditorIndex Value="8"/>
    496497        <WindowIndex Value="0"/>
    497498        <TopLine Value="31"/>
    498499        <CursorPos X="38" Y="62"/>
    499         <UsageCount Value="18"/>
     500        <UsageCount Value="19"/>
    500501        <Loaded Value="True"/>
    501502      </Unit56>
     
    510511      <Unit58>
    511512        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/dateutil.inc"/>
    512         <EditorIndex Value="1"/>
     513        <EditorIndex Value="5"/>
    513514        <WindowIndex Value="0"/>
    514515        <TopLine Value="38"/>
    515516        <CursorPos X="3" Y="50"/>
     517        <UsageCount Value="11"/>
     518        <Loaded Value="True"/>
     519      </Unit58>
     520      <Unit59>
     521        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     522        <IsVisibleTab Value="True"/>
     523        <EditorIndex Value="1"/>
     524        <WindowIndex Value="0"/>
     525        <TopLine Value="649"/>
     526        <CursorPos X="23" Y="661"/>
    516527        <UsageCount Value="10"/>
    517528        <Loaded Value="True"/>
    518       </Unit58>
     529      </Unit59>
     530      <Unit60>
     531        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/>
     532        <EditorIndex Value="4"/>
     533        <WindowIndex Value="0"/>
     534        <TopLine Value="1185"/>
     535        <CursorPos X="22" Y="1196"/>
     536        <UsageCount Value="10"/>
     537        <Loaded Value="True"/>
     538      </Unit60>
     539      <Unit61>
     540        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/types.pp"/>
     541        <UnitName Value="types"/>
     542        <EditorIndex Value="3"/>
     543        <WindowIndex Value="0"/>
     544        <TopLine Value="112"/>
     545        <CursorPos X="3" Y="124"/>
     546        <UsageCount Value="10"/>
     547        <Loaded Value="True"/>
     548      </Unit61>
    519549    </Units>
    520     <JumpHistory Count="30" HistoryIndex="29">
     550    <JumpHistory Count="30" HistoryIndex="27">
    521551      <Position1>
    522         <Filename Value="../Generic/GenericMatrix.inc"/>
    523         <Caret Line="416" Column="1" TopLine="388"/>
     552        <Filename Value="UMainForm.pas"/>
     553        <Caret Line="42" Column="51" TopLine="20"/>
    524554      </Position1>
    525555      <Position2>
    526         <Filename Value="../Generic/GenericMatrix.inc"/>
    527         <Caret Line="417" Column="1" TopLine="389"/>
     556        <Filename Value="UMainForm.pas"/>
     557        <Caret Line="458" Column="36" TopLine="440"/>
    528558      </Position2>
    529559      <Position3>
    530         <Filename Value="../Generic/GenericMatrix.inc"/>
    531         <Caret Line="408" Column="1" TopLine="389"/>
     560        <Filename Value="UMainForm.pas"/>
     561        <Caret Line="7" Column="52" TopLine="1"/>
    532562      </Position3>
    533563      <Position4>
    534         <Filename Value="../Generic/GenericMatrix.inc"/>
    535         <Caret Line="409" Column="1" TopLine="389"/>
     564        <Filename Value="UMainForm.pas"/>
     565        <Caret Line="526" Column="1" TopLine="502"/>
    536566      </Position4>
    537567      <Position5>
    538         <Filename Value="../Generic/GenericMatrix.inc"/>
    539         <Caret Line="410" Column="1" TopLine="389"/>
     568        <Filename Value="UMainForm.pas"/>
     569        <Caret Line="32" Column="49" TopLine="27"/>
    540570      </Position5>
    541571      <Position6>
    542         <Filename Value="../Generic/GenericMatrix.inc"/>
    543         <Caret Line="411" Column="1" TopLine="389"/>
     572        <Filename Value="UMainForm.pas"/>
     573        <Caret Line="416" Column="38" TopLine="312"/>
    544574      </Position6>
    545575      <Position7>
    546         <Filename Value="../Generic/GenericMatrix.inc"/>
    547         <Caret Line="412" Column="1" TopLine="389"/>
     576        <Filename Value="UMainForm.pas"/>
     577        <Caret Line="417" Column="38" TopLine="393"/>
    548578      </Position7>
    549579      <Position8>
    550         <Filename Value="../Generic/GenericMatrix.inc"/>
    551         <Caret Line="413" Column="1" TopLine="389"/>
     580        <Filename Value="UMainForm.pas"/>
     581        <Caret Line="418" Column="38" TopLine="394"/>
    552582      </Position8>
    553583      <Position9>
    554         <Filename Value="../Generic/GenericMatrix.inc"/>
    555         <Caret Line="410" Column="1" TopLine="389"/>
     584        <Filename Value="UMainForm.pas"/>
     585        <Caret Line="241" Column="3" TopLine="234"/>
    556586      </Position9>
    557587      <Position10>
    558         <Filename Value="../Generic/GenericMatrix.inc"/>
    559         <Caret Line="411" Column="1" TopLine="389"/>
     588        <Filename Value="UMainForm.pas"/>
     589        <Caret Line="377" Column="1" TopLine="361"/>
    560590      </Position10>
    561591      <Position11>
    562         <Filename Value="../Generic/GenericMatrix.inc"/>
    563         <Caret Line="413" Column="1" TopLine="389"/>
     592        <Filename Value="UMainForm.pas"/>
     593        <Caret Line="617" Column="1" TopLine="593"/>
    564594      </Position11>
    565595      <Position12>
    566         <Filename Value="../Generic/GenericMatrix.inc"/>
    567         <Caret Line="415" Column="1" TopLine="389"/>
     596        <Filename Value="UMainForm.pas"/>
     597        <Caret Line="260" Column="25" TopLine="230"/>
    568598      </Position12>
    569599      <Position13>
    570         <Filename Value="../Generic/GenericMatrix.inc"/>
    571         <Caret Line="417" Column="1" TopLine="389"/>
     600        <Filename Value="UMainForm.pas"/>
     601        <Caret Line="246" Column="21" TopLine="233"/>
    572602      </Position13>
    573603      <Position14>
    574604        <Filename Value="UMainForm.pas"/>
    575         <Caret Line="104" Column="13" TopLine="74"/>
     605        <Caret Line="364" Column="25" TopLine="358"/>
    576606      </Position14>
    577607      <Position15>
    578608        <Filename Value="UMainForm.pas"/>
    579         <Caret Line="102" Column="7" TopLine="85"/>
     609        <Caret Line="596" Column="33" TopLine="586"/>
    580610      </Position15>
    581611      <Position16>
    582612        <Filename Value="UMainForm.pas"/>
    583         <Caret Line="221" Column="64" TopLine="195"/>
     613        <Caret Line="237" Column="19" TopLine="232"/>
    584614      </Position16>
    585615      <Position17>
    586         <Filename Value="UMainForm.pas"/>
    587         <Caret Line="220" Column="49" TopLine="203"/>
     616        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     617        <Caret Line="701" Column="36" TopLine="683"/>
    588618      </Position17>
    589619      <Position18>
    590         <Filename Value="UMainForm.pas"/>
    591         <Caret Line="88" Column="16" TopLine="71"/>
     620        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     621        <Caret Line="659" Column="27" TopLine="653"/>
    592622      </Position18>
    593623      <Position19>
    594         <Filename Value="UMainForm.pas"/>
    595         <Caret Line="87" Column="1" TopLine="71"/>
     624        <Filename Value="../Generic/GenericList.inc"/>
     625        <Caret Line="468" Column="70" TopLine="462"/>
    596626      </Position19>
    597627      <Position20>
    598         <Filename Value="UMainForm.pas"/>
    599         <Caret Line="217" Column="57" TopLine="200"/>
     628        <Filename Value="../Generic/GenericList.inc"/>
     629        <Caret Line="469" Column="1" TopLine="462"/>
    600630      </Position20>
    601631      <Position21>
    602         <Filename Value="UMainForm.pas"/>
    603         <Caret Line="218" Column="55" TopLine="201"/>
     632        <Filename Value="../Generic/GenericList.inc"/>
     633        <Caret Line="470" Column="1" TopLine="462"/>
    604634      </Position21>
    605635      <Position22>
    606         <Filename Value="UMainForm.pas"/>
    607         <Caret Line="221" Column="69" TopLine="191"/>
     636        <Filename Value="../Generic/GenericList.inc"/>
     637        <Caret Line="471" Column="1" TopLine="462"/>
    608638      </Position22>
    609639      <Position23>
    610         <Filename Value="UMainForm.pas"/>
    611         <Caret Line="359" Column="19" TopLine="350"/>
     640        <Filename Value="../Generic/GenericList.inc"/>
     641        <Caret Line="470" Column="5" TopLine="462"/>
    612642      </Position23>
    613643      <Position24>
    614         <Filename Value="../Generic/GenericList.inc"/>
    615         <Caret Line="193" Column="31" TopLine="180"/>
     644        <Filename Value="UMainForm.pas"/>
     645        <Caret Line="237" Column="19" TopLine="232"/>
    616646      </Position24>
    617647      <Position25>
    618         <Filename Value="../Generic/GenericList.inc"/>
    619         <Caret Line="184" Column="20" TopLine="170"/>
     648        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     649        <Caret Line="659" Column="26" TopLine="647"/>
    620650      </Position25>
    621651      <Position26>
    622         <Filename Value="../Generic/GenericList.inc"/>
    623         <Caret Line="184" Column="19" TopLine="170"/>
     652        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/>
     653        <Caret Line="1193" Column="20" TopLine="1185"/>
    624654      </Position26>
    625655      <Position27>
    626         <Filename Value="UMainForm.pas"/>
    627         <Caret Line="42" Column="51" TopLine="20"/>
     656        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/>
     657        <Caret Line="1196" Column="22" TopLine="1185"/>
    628658      </Position27>
    629659      <Position28>
    630         <Filename Value="UMainForm.pas"/>
    631         <Caret Line="458" Column="36" TopLine="440"/>
     660        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     661        <Caret Line="661" Column="23" TopLine="649"/>
    632662      </Position28>
    633663      <Position29>
    634         <Filename Value="UMainForm.pas"/>
    635         <Caret Line="7" Column="52" TopLine="1"/>
     664        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     665        <Caret Line="657" Column="48" TopLine="644"/>
    636666      </Position29>
    637667      <Position30>
    638         <Filename Value="UMainForm.pas"/>
    639         <Caret Line="526" Column="1" TopLine="502"/>
     668        <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/>
     669        <Caret Line="651" Column="3" TopLine="639"/>
    640670      </Position30>
    641671    </JumpHistory>
  • Generics/TemplateGenerics/Demo/UMainForm.lfm

    r110 r111  
    5656    TabOrder = 4
    5757  end
    58   object ButtonBenchmarkList: TButton
    59     Left = 8
     58  object ButtonBenchmarkListString: TButton
     59    Left = 10
    6060    Height = 24
    61     Top = 491
     61    Top = 456
    6262    Width = 128
    6363    Anchors = [akLeft, akBottom]
    64     Caption = 'Benchmark list'
    65     OnClick = ButtonBenchmarkListClick
     64    Caption = 'TListString'
     65    OnClick = ButtonBenchmarkListStringClick
    6666    TabOrder = 5
    6767  end
     
    7878    Left = 10
    7979    Height = 25
    80     Top = 459
     80    Top = 424
    8181    Width = 126
    8282    Anchors = [akLeft, akBottom]
    83     Caption = 'Benchmark dictionary'
     83    Caption = 'TDictionaryStringString'
    8484    OnClick = ButtonBenchmarkDictionaryClick
    8585    TabOrder = 7
     
    121121    ParentColor = False
    122122  end
     123  object Label1: TLabel
     124    Left = 10
     125    Height = 14
     126    Top = 408
     127    Width = 62
     128    Anchors = [akLeft, akBottom]
     129    Caption = 'Benchmarks:'
     130    ParentColor = False
     131  end
     132  object ButtonBenchmarkListPointer: TButton
     133    Left = 8
     134    Height = 24
     135    Top = 488
     136    Width = 128
     137    Anchors = [akLeft, akBottom]
     138    Caption = 'TListPointer'
     139    OnClick = ButtonBenchmarkListPointerClick
     140    TabOrder = 10
     141  end
    123142end
  • Generics/TemplateGenerics/Demo/UMainForm.pas

    r110 r111  
    1616  TMainForm = class(TForm)
    1717    ButtonBenchmarkDictionary: TButton;
     18    ButtonBenchmarkListPointer: TButton;
    1819    ButtonListObject: TButton;
    19     ButtonBenchmarkList: TButton;
     20    ButtonBenchmarkListString: TButton;
    2021    ButtonCharList: TButton;
    2122    ButtonMatrixInteger: TButton;
     
    2425    ButtonIntegerList: TButton;
    2526    ButtonStringList: TButton;
     27    Label1: TLabel;
    2628    LabelTestName: TLabel;
    2729    ListViewOutput: TListView;
    2830    procedure ButtonBenchmarkDictionaryClick(Sender: TObject);
    29     procedure ButtonBenchmarkListClick(Sender: TObject);
     31    procedure ButtonBenchmarkListPointerClick(Sender: TObject);
     32    procedure ButtonBenchmarkListStringClick(Sender: TObject);
    3033    procedure ButtonCharListClick(Sender: TObject);
    3134    procedure ButtonDictionaryStringClick(Sender: TObject);
     
    229232end;
    230233
    231 procedure TMainForm.ButtonBenchmarkListClick(Sender: TObject);
    232 var
    233   List: TListPointer;
    234   List2: TList;
     234procedure TMainForm.ButtonBenchmarkListStringClick(Sender: TObject);
     235var
     236  List: TListString;
     237  List2: TStringList;
    235238  StartTime: TDateTime;
    236239  I: Integer;
    237 begin
    238   LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TList benchmark';
     240const
     241  SampleText: string = 'text';
     242  SampleCount: Integer = 100000;
     243begin
     244  LabelTestName.Caption := 'Generic specialized TListString vs. classic non-generic TStringList benchmark';
    239245  ListViewOutput.Clear;
    240246  try
    241247    UpdateButtonState(False);
    242     List := TListPointer.Create;
    243     List2 := TList.Create;
    244 
    245     StartTime := Now;
    246     repeat
    247       List.Add(1);
    248     until (Now - StartTime) > MeasureDuration;
    249     WriteOutput('TListPointer.Add', IntToStr(List.Count) + ' ops/sec');
    250     List.Clear;
    251     Application.ProcessMessages;
    252 
    253     StartTime := Now;
    254     repeat
    255       List2.Add(1);
    256     until (Now - StartTime) > MeasureDuration;
    257     WriteOutput('TList.Add', IntToStr(List2.Count) + ' ops/sec');
     248    List := TListString.Create;
     249    List2 := TStringList.Create;
     250
     251    StartTime := Now;
     252    repeat
     253      List.Add(SampleText);
     254    until (Now - StartTime) > MeasureDuration;
     255    WriteOutput('TListString.Add', IntToStr(List.Count) + ' ops');
     256    List.Clear;
     257    Application.ProcessMessages;
     258
     259    StartTime := Now;
     260    repeat
     261      List2.Add(SampleText);
     262    until (Now - StartTime) > MeasureDuration;
     263    WriteOutput('TStringList.Add', IntToStr(List2.Count) + ' ops');
    258264    List2.Clear;
    259265    Application.ProcessMessages;
     
    261267    StartTime := Now;
    262268    repeat
    263       List.Insert(0, 1);
    264     until (Now - StartTime) > MeasureDuration;
    265     WriteOutput('TListPointer.Insert', IntToStr(List.Count) + ' ops/sec');
    266     List.Clear;
    267     Application.ProcessMessages;
    268 
    269     StartTime := Now;
    270     repeat
    271       List2.Insert(0, 1);
    272     until (Now - StartTime) > MeasureDuration;
    273     WriteOutput('TList.Insert', IntToStr(List2.Count) + ' ops/sec');
     269      List.Insert(0, SampleText);
     270    until (Now - StartTime) > MeasureDuration;
     271    WriteOutput('TListString.Insert', IntToStr(List.Count) + ' ops');
     272    List.Clear;
     273    Application.ProcessMessages;
     274
     275    StartTime := Now;
     276    repeat
     277      List2.Insert(0, SampleText);
     278    until (Now - StartTime) > MeasureDuration;
     279    WriteOutput('TStringList.Insert', IntToStr(List2.Count) + ' ops');
    274280    List2.Clear;
    275281    Application.ProcessMessages;
    276282
    277     for I := 0 to 1000000 do
    278       List.Add(1);
     283    for I := 0 to SampleCount - 1 do
     284      List.Add(SampleText);
    279285    StartTime := Now;
    280286    I := 0;
     
    283289      Inc(I);
    284290    until (Now - StartTime) > MeasureDuration;
    285     WriteOutput('TListPointer.Delete', IntToStr(I) + ' ops/sec');
    286     List.Clear;
    287     Application.ProcessMessages;
    288 
    289     for I := 0 to 1000000 do
    290       List2.Add(1);
     291    WriteOutput('TListString.Delete', IntToStr(I) + ' ops');
     292    List.Clear;
     293    Application.ProcessMessages;
     294
     295    for I := 0 to SampleCount - 1 do
     296      List2.Add(SampleText);
    291297    StartTime := Now;
    292298    I := 0;
     
    295301      Inc(I);
    296302    until (Now - StartTime) > MeasureDuration;
    297     WriteOutput('TList.Delete', IntToStr(I) + ' ops/sec');
    298     Application.ProcessMessages;
    299 
    300     for I := 0 to 1000000 do
    301       List.Add(1);
    302     StartTime := Now;
    303     I := 0;
    304     repeat
    305       List.Move(300000, 700000);
    306       Inc(I);
    307     until (Now - StartTime) > MeasureDuration;
    308     WriteOutput('TListPointer.Move', IntToStr(I) + ' ops/sec');
    309     List.Clear;
    310     Application.ProcessMessages;
    311 
    312     for I := 0 to 1000000 do
    313     List2.Add(1);
    314     StartTime := Now;
    315     I := 0;
    316     repeat
    317       List2.Move(300000, 700000);
    318       Inc(I);
    319     until (Now - StartTime) > MeasureDuration;
    320     WriteOutput('TList.Move', IntToStr(I) + ' ops/sec');
    321     Application.ProcessMessages;
    322 
    323     for I := 0 to 1000000 do
    324       List.Add(1);
    325     StartTime := Now;
    326     I := 0;
    327     repeat
    328       List.Exchange(300000, 700000);
    329       Inc(I);
    330     until (Now - StartTime) > MeasureDuration;
    331     WriteOutput('TListPointer.Exchange', IntToStr(I) + ' ops/sec');
    332     List.Clear;
    333     Application.ProcessMessages;
    334 
    335     for I := 0 to 1000000 do
    336     List2.Add(1);
    337     StartTime := Now;
    338     I := 0;
    339     repeat
    340       List2.Exchange(300000, 700000);
    341       Inc(I);
    342     until (Now - StartTime) > MeasureDuration;
    343     WriteOutput('TList.Exchange', IntToStr(I) + ' ops/sec');
    344     Application.ProcessMessages;
    345 
    346     for I := 0 to 1000000 do
    347       List.Add(1);
    348     StartTime := Now;
    349     I := 0;
    350     repeat
    351       List.IndexOf(Pointer(I mod List.Count));
    352       Inc(I);
    353     until (Now - StartTime) > MeasureDuration;
    354     WriteOutput('TListPointer.IndexOf', IntToStr(I) + ' ops/sec');
    355     List.Clear;
    356     Application.ProcessMessages;
    357 
    358     for I := 0 to 1000000 do
    359     List2.Add(1);
    360     StartTime := Now;
    361     I := 0;
    362     repeat
    363       List2.IndexOf(Pointer(I mod List2.Count));
    364       Inc(I);
    365     until (Now - StartTime) > MeasureDuration;
    366     WriteOutput('TList.IndexOf', IntToStr(I) + ' ops/sec');
     303    WriteOutput('TStringList.Delete', IntToStr(I) + ' ops');
     304    Application.ProcessMessages;
     305
     306    for I := 0 to SampleCount - 1 do
     307      List.Add(SampleText);
     308    StartTime := Now;
     309    I := 0;
     310    repeat
     311      List.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     312      Inc(I);
     313    until (Now - StartTime) > MeasureDuration;
     314    WriteOutput('TListString.Move', IntToStr(I) + ' ops');
     315    List.Clear;
     316    Application.ProcessMessages;
     317
     318    for I := 0 to SampleCount - 1 do
     319      List2.Add(SampleText);
     320    StartTime := Now;
     321    I := 0;
     322    repeat
     323      List2.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     324      Inc(I);
     325    until (Now - StartTime) > MeasureDuration;
     326    WriteOutput('TStringList.Move', IntToStr(I) + ' ops');
     327    Application.ProcessMessages;
     328
     329    for I := 0 to SampleCount - 1 do
     330      List.Add(SampleText);
     331    StartTime := Now;
     332    I := 0;
     333    repeat
     334      List.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     335      Inc(I);
     336    until (Now - StartTime) > MeasureDuration;
     337    WriteOutput('TListString.Exchange', IntToStr(I) + ' ops');
     338    List.Clear;
     339    Application.ProcessMessages;
     340
     341    for I := 0 to SampleCount - 1 do
     342    List2.Add(SampleText);
     343    StartTime := Now;
     344    I := 0;
     345    repeat
     346      List2.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     347      Inc(I);
     348    until (Now - StartTime) > MeasureDuration;
     349    WriteOutput('TStringList.Exchange', IntToStr(I) + ' ops');
     350    Application.ProcessMessages;
     351
     352    for I := 0 to SampleCount - 1 do
     353      List.Add(SampleText + IntToStr(I));
     354    StartTime := Now;
     355    I := 0;
     356    repeat
     357      List.IndexOf(SampleText + IntToStr(I mod List.Count));
     358      Inc(I);
     359    until (Now - StartTime) > MeasureDuration;
     360    WriteOutput('TListString.IndexOf', IntToStr(I) + ' ops');
     361    List.Clear;
     362    Application.ProcessMessages;
     363
     364    for I := 0 to SampleCount - 1 do
     365      List2.Add(SampleText + IntToStr(I));
     366    StartTime := Now;
     367    I := 0;
     368    repeat
     369      List2.IndexOf(SampleText + IntToStr(I mod List2.Count));
     370      Inc(I);
     371    until (Now - StartTime) > MeasureDuration;
     372    WriteOutput('TStringList.IndexOf', IntToStr(I) + ' ops');
    367373    Application.ProcessMessages;
    368374
     
    396402      I := I + 1;
    397403    until (Now - StartTime) > MeasureDuration;
    398     WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.Count) + ' ops/sec');
     404    WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.Count) + ' ops');
    399405    Application.ProcessMessages;
    400406
     
    405411      I := I + 1;
    406412    until (Now - StartTime) > MeasureDuration;
    407     WriteOutput('TStringList.Add', IntToStr(Dictionary2.Count) + ' ops/sec');
     413    WriteOutput('TStringList.Add', IntToStr(Dictionary2.Count) + ' ops');
    408414    Application.ProcessMessages;
    409415
     
    414420      I := I + 1;
    415421    until (Now - StartTime) > MeasureDuration;
    416     WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops/sec');
     422    WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops');
    417423    Application.ProcessMessages;
    418424
     
    423429      I := I + 1;
    424430    until (Now - StartTime) > MeasureDuration;
    425     WriteOutput('TStringList.Values', IntToStr(I) + ' ops/sec');
     431    WriteOutput('TStringList.Values', IntToStr(I) + ' ops');
    426432    Application.ProcessMessages;
    427433
     
    432438      I := I + 1;
    433439    until (Now - StartTime) > MeasureDuration;
    434     WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops/sec');
     440    WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops');
    435441    Application.ProcessMessages;
    436442
     
    441447      I := I + 1;
    442448    until (Now - StartTime) > MeasureDuration;
    443     WriteOutput('TStringList.Keys(Names)', IntToStr(I) + ' ops/sec');
     449    WriteOutput('TStringList.Keys(Names)', IntToStr(I) + ' ops');
    444450    Application.ProcessMessages;
    445451
     
    450456      I := I + 1;
    451457    until (Now - StartTime) > MeasureDuration;
    452     WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops/sec');
     458    WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops');
    453459    Application.ProcessMessages;
    454460
     
    459465      I := I + 1;
    460466    until (Now - StartTime) > MeasureDuration;
    461     WriteOutput('TStringList.Items(ValueFromIndex)', IntToStr(I) + ' ops/sec');
     467    WriteOutput('TStringList.Items(ValueFromIndex)', IntToStr(I) + ' ops');
    462468    Application.ProcessMessages;
    463469
     
    466472    Dictionary.Free;
    467473    Dictionary2.Free;
     474  end;
     475end;
     476
     477procedure TMainForm.ButtonBenchmarkListPointerClick(Sender: TObject);
     478var
     479  List: TListPointer;
     480  List2: TList;
     481  StartTime: TDateTime;
     482  I: Integer;
     483const
     484  SampleCount: Integer = 100000;
     485begin
     486  LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TList benchmark';
     487  ListViewOutput.Clear;
     488  try
     489    UpdateButtonState(False);
     490    List := TListPointer.Create;
     491    List2 := TList.Create;
     492
     493    StartTime := Now;
     494    repeat
     495      List.Add(1);
     496    until (Now - StartTime) > MeasureDuration;
     497    WriteOutput('TListPointer.Add', IntToStr(List.Count) + ' ops');
     498    List.Clear;
     499    Application.ProcessMessages;
     500
     501    StartTime := Now;
     502    repeat
     503      List2.Add(1);
     504    until (Now - StartTime) > MeasureDuration;
     505    WriteOutput('TList.Add', IntToStr(List2.Count) + ' ops');
     506    List2.Clear;
     507    Application.ProcessMessages;
     508
     509    StartTime := Now;
     510    repeat
     511      List.Insert(0, 1);
     512    until (Now - StartTime) > MeasureDuration;
     513    WriteOutput('TListPointer.Insert', IntToStr(List.Count) + ' ops');
     514    List.Clear;
     515    Application.ProcessMessages;
     516
     517    StartTime := Now;
     518    repeat
     519      List2.Insert(0, 1);
     520    until (Now - StartTime) > MeasureDuration;
     521    WriteOutput('TList.Insert', IntToStr(List2.Count) + ' ops');
     522    List2.Clear;
     523    Application.ProcessMessages;
     524
     525    for I := 0 to SampleCount - 1 do
     526      List.Add(1);
     527    StartTime := Now;
     528    I := 0;
     529    repeat
     530      List.Delete(0);
     531      Inc(I);
     532    until (Now - StartTime) > MeasureDuration;
     533    WriteOutput('TListPointer.Delete', IntToStr(I) + ' ops');
     534    List.Clear;
     535    Application.ProcessMessages;
     536
     537    for I := 0 to SampleCount - 1 do
     538      List2.Add(1);
     539    StartTime := Now;
     540    I := 0;
     541    repeat
     542      List2.Delete(0);
     543      Inc(I);
     544    until (Now - StartTime) > MeasureDuration;
     545    WriteOutput('TList.Delete', IntToStr(I) + ' ops');
     546    Application.ProcessMessages;
     547
     548    for I := 0 to SampleCount - 1 do
     549      List.Add(1);
     550    StartTime := Now;
     551    I := 0;
     552    repeat
     553      List.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     554      Inc(I);
     555    until (Now - StartTime) > MeasureDuration;
     556    WriteOutput('TListPointer.Move', IntToStr(I) + ' ops');
     557    List.Clear;
     558    Application.ProcessMessages;
     559
     560    for I := 0 to SampleCount - 1 do
     561    List2.Add(1);
     562    StartTime := Now;
     563    I := 0;
     564    repeat
     565      List2.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     566      Inc(I);
     567    until (Now - StartTime) > MeasureDuration;
     568    WriteOutput('TList.Move', IntToStr(I) + ' ops');
     569    Application.ProcessMessages;
     570
     571    for I := 0 to SampleCount - 1 do
     572      List.Add(1);
     573    StartTime := Now;
     574    I := 0;
     575    repeat
     576      List.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     577      Inc(I);
     578    until (Now - StartTime) > MeasureDuration;
     579    WriteOutput('TListPointer.Exchange', IntToStr(I) + ' ops');
     580    List.Clear;
     581    Application.ProcessMessages;
     582
     583    for I := 0 to SampleCount - 1 do
     584    List2.Add(1);
     585    StartTime := Now;
     586    I := 0;
     587    repeat
     588      List2.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7));
     589      Inc(I);
     590    until (Now - StartTime) > MeasureDuration;
     591    WriteOutput('TList.Exchange', IntToStr(I) + ' ops');
     592    Application.ProcessMessages;
     593
     594    for I := 0 to SampleCount - 1 do
     595      List.Add(1);
     596    StartTime := Now;
     597    I := 0;
     598    repeat
     599      List.IndexOf(Pointer(I mod List.Count));
     600      Inc(I);
     601    until (Now - StartTime) > MeasureDuration;
     602    WriteOutput('TListPointer.IndexOf', IntToStr(I) + ' ops');
     603    List.Clear;
     604    Application.ProcessMessages;
     605
     606    for I := 0 to SampleCount - 1 do
     607    List2.Add(1);
     608    StartTime := Now;
     609    I := 0;
     610    repeat
     611      List2.IndexOf(Pointer(I mod List2.Count));
     612      Inc(I);
     613    until (Now - StartTime) > MeasureDuration;
     614    WriteOutput('TList.IndexOf', IntToStr(I) + ' ops');
     615    Application.ProcessMessages;
     616
     617  finally
     618    UpdateButtonState(True);
     619    List.Free;
     620    List2.Free;
    468621  end;
    469622end;
     
    504657begin
    505658  ButtonBenchmarkDictionary.Enabled := Enabled;
    506   ButtonBenchmarkList.Enabled := Enabled;
     659  ButtonBenchmarkListString.Enabled := Enabled;
    507660  ButtonCharList.Enabled := Enabled;
    508661  ButtonDictionaryString.Enabled := Enabled;
Note: See TracChangeset for help on using the changeset viewer.