Ignore:
Timestamp:
Jan 3, 2011, 8:23:44 AM (13 years ago)
Author:
george
Message:
  • Added: TListString benchmark.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.