Ignore:
Timestamp:
Jan 3, 2011, 7:30:09 AM (14 years ago)
Author:
george
Message:
  • Added: Disable buttons during benchmarks.
  • Modified: Benchmark duration reduced from 1 second to 100 ms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Demo/UMainForm.pas

    r109 r110  
    3939  private
    4040  public
     41    MeasureDuration: TDateTime;
    4142    Bitmap: TBitmap;
     43    procedure UpdateButtonState(Enabled: Boolean);
    4244    procedure WriteOutput(Text1: string = ''; Text2: string = '');
    4345  end;
     
    5456procedure TMainForm.FormCreate(Sender: TObject);
    5557begin
     58  MeasureDuration := 100 * OneMillisecond;
    5659end;
    5760
     
    236239  ListViewOutput.Clear;
    237240  try
     241    UpdateButtonState(False);
    238242    List := TListPointer.Create;
    239243    List2 := TList.Create;
     
    242246    repeat
    243247      List.Add(1);
    244     until (Now - StartTime) > OneSecond;
     248    until (Now - StartTime) > MeasureDuration;
    245249    WriteOutput('TListPointer.Add', IntToStr(List.Count) + ' ops/sec');
    246250    List.Clear;
     
    250254    repeat
    251255      List2.Add(1);
    252     until (Now - StartTime) > OneSecond;
     256    until (Now - StartTime) > MeasureDuration;
    253257    WriteOutput('TList.Add', IntToStr(List2.Count) + ' ops/sec');
    254258    List2.Clear;
     
    258262    repeat
    259263      List.Insert(0, 1);
    260     until (Now - StartTime) > OneSecond;
     264    until (Now - StartTime) > MeasureDuration;
    261265    WriteOutput('TListPointer.Insert', IntToStr(List.Count) + ' ops/sec');
    262266    List.Clear;
     
    266270    repeat
    267271      List2.Insert(0, 1);
    268     until (Now - StartTime) > OneSecond;
     272    until (Now - StartTime) > MeasureDuration;
    269273    WriteOutput('TList.Insert', IntToStr(List2.Count) + ' ops/sec');
    270274    List2.Clear;
     
    278282      List.Delete(0);
    279283      Inc(I);
    280     until (Now - StartTime) > OneSecond;
     284    until (Now - StartTime) > MeasureDuration;
    281285    WriteOutput('TListPointer.Delete', IntToStr(I) + ' ops/sec');
    282286    List.Clear;
     
    290294      List2.Delete(0);
    291295      Inc(I);
    292     until (Now - StartTime) > OneSecond;
     296    until (Now - StartTime) > MeasureDuration;
    293297    WriteOutput('TList.Delete', IntToStr(I) + ' ops/sec');
    294298    Application.ProcessMessages;
     
    301305      List.Move(300000, 700000);
    302306      Inc(I);
    303     until (Now - StartTime) > OneSecond;
     307    until (Now - StartTime) > MeasureDuration;
    304308    WriteOutput('TListPointer.Move', IntToStr(I) + ' ops/sec');
    305309    List.Clear;
     
    313317      List2.Move(300000, 700000);
    314318      Inc(I);
    315     until (Now - StartTime) > OneSecond;
     319    until (Now - StartTime) > MeasureDuration;
    316320    WriteOutput('TList.Move', IntToStr(I) + ' ops/sec');
    317321    Application.ProcessMessages;
     
    324328      List.Exchange(300000, 700000);
    325329      Inc(I);
    326     until (Now - StartTime) > OneSecond;
     330    until (Now - StartTime) > MeasureDuration;
    327331    WriteOutput('TListPointer.Exchange', IntToStr(I) + ' ops/sec');
    328332    List.Clear;
     
    336340      List2.Exchange(300000, 700000);
    337341      Inc(I);
    338     until (Now - StartTime) > OneSecond;
     342    until (Now - StartTime) > MeasureDuration;
    339343    WriteOutput('TList.Exchange', IntToStr(I) + ' ops/sec');
    340344    Application.ProcessMessages;
     
    347351      List.IndexOf(Pointer(I mod List.Count));
    348352      Inc(I);
    349     until (Now - StartTime) > OneSecond;
     353    until (Now - StartTime) > MeasureDuration;
    350354    WriteOutput('TListPointer.IndexOf', IntToStr(I) + ' ops/sec');
    351355    List.Clear;
     
    359363      List2.IndexOf(Pointer(I mod List2.Count));
    360364      Inc(I);
    361     until (Now - StartTime) > OneSecond;
     365    until (Now - StartTime) > MeasureDuration;
    362366    WriteOutput('TList.IndexOf', IntToStr(I) + ' ops/sec');
    363367    Application.ProcessMessages;
    364368
    365369  finally
     370    UpdateButtonState(True);
    366371    List.Free;
    367372    List2.Free;
     
    380385  ListViewOutput.Clear;
    381386  try
     387    UpdateButtonState(False);
    382388    Dictionary := TDictionaryStringString.Create;
    383389    Dictionary2 := TStringList.Create;
     
    389395      Dictionary.Add(IntToStr(I), IntToStr(I));
    390396      I := I + 1;
    391     until (Now - StartTime) > OneSecond;
     397    until (Now - StartTime) > MeasureDuration;
    392398    WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.Count) + ' ops/sec');
    393399    Application.ProcessMessages;
     
    398404      Dictionary2.Add(IntToStr(I) + Dictionary2.NameValueSeparator + IntToStr(I));
    399405      I := I + 1;
    400     until (Now - StartTime) > OneSecond;
     406    until (Now - StartTime) > MeasureDuration;
    401407    WriteOutput('TStringList.Add', IntToStr(Dictionary2.Count) + ' ops/sec');
    402408    Application.ProcessMessages;
     
    407413      R := Dictionary.Values[IntToStr(I mod Dictionary.Count)];
    408414      I := I + 1;
    409     until (Now - StartTime) > OneSecond;
     415    until (Now - StartTime) > MeasureDuration;
    410416    WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops/sec');
    411417    Application.ProcessMessages;
     
    416422      R := Dictionary2.Values[IntToStr(I mod Dictionary2.Count)];
    417423      I := I + 1;
    418     until (Now - StartTime) > OneSecond;
     424    until (Now - StartTime) > MeasureDuration;
    419425    WriteOutput('TStringList.Values', IntToStr(I) + ' ops/sec');
    420426    Application.ProcessMessages;
     
    425431      R := Dictionary.Keys[I mod Dictionary.Count];
    426432      I := I + 1;
    427     until (Now - StartTime) > OneSecond;
     433    until (Now - StartTime) > MeasureDuration;
    428434    WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops/sec');
    429435    Application.ProcessMessages;
     
    434440      R := Dictionary2.Names[I mod Dictionary2.Count];
    435441      I := I + 1;
    436     until (Now - StartTime) > OneSecond;
     442    until (Now - StartTime) > MeasureDuration;
    437443    WriteOutput('TStringList.Keys(Names)', IntToStr(I) + ' ops/sec');
    438444    Application.ProcessMessages;
     
    443449      R := Dictionary.Items[I mod Dictionary.Count].Value;
    444450      I := I + 1;
    445     until (Now - StartTime) > OneSecond;
     451    until (Now - StartTime) > MeasureDuration;
    446452    WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops/sec');
    447453    Application.ProcessMessages;
     
    452458      R := Dictionary2.ValueFromIndex[I mod Dictionary2.Count];
    453459      I := I + 1;
    454     until (Now - StartTime) > OneSecond;
     460    until (Now - StartTime) > MeasureDuration;
    455461    WriteOutput('TStringList.Items(ValueFromIndex)', IntToStr(I) + ' ops/sec');
    456462    Application.ProcessMessages;
    457463
    458464  finally
     465    UpdateButtonState(True);
    459466    Dictionary.Free;
    460467    Dictionary2.Free;
     
    494501end;
    495502
     503procedure TMainForm.UpdateButtonState(Enabled: Boolean);
     504begin
     505  ButtonBenchmarkDictionary.Enabled := Enabled;
     506  ButtonBenchmarkList.Enabled := Enabled;
     507  ButtonCharList.Enabled := Enabled;
     508  ButtonDictionaryString.Enabled := Enabled;
     509  ButtonIntegerList.Enabled := Enabled;
     510  ButtonListObject.Enabled := Enabled;
     511  ButtonMatrixInteger.Enabled := Enabled;
     512  ButtonQueueInteger.Enabled := Enabled;
     513  ButtonStringList.Enabled := Enabled;
     514end;
     515
    496516procedure TMainForm.WriteOutput(Text1: string = ''; Text2: string = '');
    497517var
Note: See TracChangeset for help on using the changeset viewer.