Changeset 80 for Generics/TemplateGenerics/Demo/UMainForm.pas
- Timestamp:
- Oct 30, 2010, 7:31:20 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Demo/UMainForm.pas
r79 r80 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ListInteger, ListString, DictionaryString , QueueInteger, ListChar,10 ListPointer, DateUtils, List Variant, Contnrs, ListObject;9 ComCtrls, ListInteger, ListString, DictionaryStringString, QueueInteger, ListChar, 10 ListPointer, DateUtils, ListObject; 11 11 12 12 type … … 15 15 16 16 TMainForm = class(TForm) 17 ButtonBenchmarkDictionary: TButton; 17 18 ButtonListObject: TButton; 18 ButtonBenchmark : TButton;19 ButtonBenchmarkList: TButton; 19 20 ButtonCharList: TButton; 20 21 ButtonQueueInteger: TButton; … … 23 24 ButtonStringList: TButton; 24 25 MemoOutput: TMemo; 25 procedure ButtonBenchmarkClick(Sender: TObject); 26 procedure ButtonBenchmarkDictionaryClick(Sender: TObject); 27 procedure ButtonBenchmarkListClick(Sender: TObject); 26 28 procedure ButtonCharListClick(Sender: TObject); 27 29 procedure ButtonDictionaryStringClick(Sender: TObject); … … 132 134 end; 133 135 134 function StringPairToStr(Pair: TPairString ): string;136 function StringPairToStr(Pair: TPairStringString): string; 135 137 begin 136 138 Result := Pair.Key + ':' + Pair.Value; … … 139 141 procedure TMainForm.ButtonDictionaryStringClick(Sender: TObject); 140 142 var 141 Dictionary: TDictionaryString ;143 Dictionary: TDictionaryStringString; 142 144 begin 143 145 MemoOutput.Clear; 144 146 WriteLn('TDictionaryString test'); 145 Dictionary := TDictionaryString .Create;147 Dictionary := TDictionaryStringString.Create; 146 148 with Dictionary do try 147 149 Add('Key1', 'Value1'); … … 193 195 end; 194 196 195 procedure TMainForm.ButtonBenchmark Click(Sender: TObject);197 procedure TMainForm.ButtonBenchmarkListClick(Sender: TObject); 196 198 var 197 199 List: TListPointer; … … 336 338 finally 337 339 List2.Free; 340 end; 341 end; 342 343 procedure TMainForm.ButtonBenchmarkDictionaryClick(Sender: TObject); 344 var 345 Dictionary: TDictionaryStringString; 346 Dictionary2: TStringList; 347 StartTime: TDateTime; 348 I: Integer; 349 R: string; 350 begin 351 MemoOutput.Clear; 352 try 353 Dictionary := TDictionaryStringString.Create; 354 WriteLn('TDictionaryStringString...'); 355 I := 0; 356 StartTime := Now; 357 repeat 358 Dictionary.Add(IntToStr(I), IntToStr(I)); 359 I := I + 1; 360 until (Now - StartTime) > OneSecond; 361 WriteLn('Add pair: ' + IntToStr(Dictionary.Count) + ' ops/sec'); 362 Application.ProcessMessages; 363 364 I := 0; 365 StartTime := Now; 366 repeat 367 R := Dictionary.Values[IntToStr(I mod Dictionary.Count)]; 368 I := I + 1; 369 until (Now - StartTime) > OneSecond; 370 WriteLn('Values: ' + IntToStr(I) + ' ops/sec'); 371 Application.ProcessMessages; 372 373 I := 0; 374 StartTime := Now; 375 repeat 376 R := Dictionary.Keys[I mod Dictionary.Count]; 377 I := I + 1; 378 until (Now - StartTime) > OneSecond; 379 WriteLn('Keys: ' + IntToStr(I) + ' ops/sec'); 380 Application.ProcessMessages; 381 382 I := 0; 383 StartTime := Now; 384 repeat 385 R := Dictionary.Items[I mod Dictionary.Count].Value; 386 I := I + 1; 387 until (Now - StartTime) > OneSecond; 388 WriteLn('Values by index: ' + IntToStr(I) + ' ops/sec'); 389 Application.ProcessMessages; 390 finally 391 Dictionary.Free; 392 end; 393 394 try 395 Dictionary2 := TStringList.Create; 396 Dictionary2.NameValueSeparator := '|'; 397 WriteLn('TStringList...'); 398 I := 0; 399 StartTime := Now; 400 repeat 401 Dictionary2.Add(IntToStr(I) + Dictionary2.NameValueSeparator + IntToStr(I)); 402 I := I + 1; 403 until (Now - StartTime) > OneSecond; 404 WriteLn('Add pair: ' + IntToStr(Dictionary2.Count) + ' ops/sec'); 405 Application.ProcessMessages; 406 407 I := 0; 408 StartTime := Now; 409 repeat 410 R := Dictionary2.Values[IntToStr(I mod Dictionary2.Count)]; 411 I := I + 1; 412 until (Now - StartTime) > OneSecond; 413 WriteLn('Values: ' + IntToStr(I) + ' ops/sec'); 414 Application.ProcessMessages; 415 416 I := 0; 417 StartTime := Now; 418 repeat 419 R := Dictionary2.Names[I mod Dictionary2.Count]; 420 I := I + 1; 421 until (Now - StartTime) > OneSecond; 422 WriteLn('Keys: ' + IntToStr(I) + ' ops/sec'); 423 Application.ProcessMessages; 424 425 I := 0; 426 StartTime := Now; 427 repeat 428 R := Dictionary2.ValueFromIndex[I mod Dictionary2.Count]; 429 I := I + 1; 430 until (Now - StartTime) > OneSecond; 431 WriteLn('Values by index: ' + IntToStr(I) + ' ops/sec'); 432 Application.ProcessMessages; 433 finally 434 Dictionary2.Free; 338 435 end; 339 436 end;
Note:
See TracChangeset
for help on using the changeset viewer.