Changeset 496 for Generics/NativeGenerics/Demo/UMainForm.pas
- Timestamp:
- Jan 5, 2018, 10:24:36 PM (7 years ago)
- Location:
- Generics/NativeGenerics/Demo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Demo
- Property svn:ignore
-
old new 3 3 Demo.exe 4 4 heaptrclog.trc 5 Demo
-
- Property svn:ignore
-
Generics/NativeGenerics/Demo/UMainForm.pas
r481 r496 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, GenericList, GenericDictionary, GenericQueue, GenericStream,10 DateUtils, GenericString, GenericTree;9 ComCtrls, DateUtils, GenericList, GenericMatrix, GenericQueue, fgl, 10 GenericDictionary, SpecializedStream, SpecializedList; 11 11 12 12 type … … 15 15 16 16 TMainForm = class(TForm) 17 TreeButton: TButton; 18 StreamByteButton: TButton; 17 ButtonStreamByte: TButton; 19 18 ButtonBenchmarkDictionary: TButton; 20 19 ButtonBenchmarkListPointer: TButton; 21 ListObjectButton: TButton;20 ButtonListObject: TButton; 22 21 ButtonBenchmarkListString: TButton; 23 CharListButton: TButton;24 MatrixIntegerButton: TButton;25 QueueIntegerButton: TButton;26 DictionaryStringButton: TButton;27 IntegerListButton: TButton;28 StringListButton: TButton;22 ButtonCharList: TButton; 23 ButtonMatrixInteger: TButton; 24 ButtonQueueInteger: TButton; 25 ButtonDictionaryString: TButton; 26 ButtonIntegerList: TButton; 27 ButtonStringList: TButton; 29 28 Label1: TLabel; 30 29 LabelTestName: TLabel; … … 33 32 procedure ButtonBenchmarkListPointerClick(Sender: TObject); 34 33 procedure ButtonBenchmarkListStringClick(Sender: TObject); 35 procedure CharListButtonClick(Sender: TObject);36 procedure DictionaryStringButtonClick(Sender: TObject);37 procedure IntegerListButtonClick(Sender: TObject);38 procedure MatrixIntegerButtonClick(Sender: TObject);39 procedure ListObjectButtonClick(Sender: TObject);40 procedure QueueIntegerButtonClick(Sender: TObject);41 procedure StreamByteButtonClick(Sender: TObject);42 procedure StringListButtonClick(Sender: TObject);34 procedure ButtonCharListClick(Sender: TObject); 35 procedure ButtonDictionaryStringClick(Sender: TObject); 36 procedure ButtonIntegerListClick(Sender: TObject); 37 procedure ButtonMatrixIntegerClick(Sender: TObject); 38 procedure ButtonListObjectClick(Sender: TObject); 39 procedure ButtonQueueIntegerClick(Sender: TObject); 40 procedure ButtonStringListClick(Sender: TObject); 41 procedure ButtonStreamByteClick(Sender: TObject); 43 42 procedure FormCreate(Sender: TObject); 44 43 procedure FormDestroy(Sender: TObject); 45 procedure TreeButtonClick(Sender: TObject);46 private47 44 public 48 45 MeasureDuration: TDateTime; 46 Bitmap: TBitmap; 49 47 procedure UpdateButtonState(Enabled: Boolean); 50 48 procedure WriteOutput(Text1: string = ''; Text2: string = ''); … … 65 63 end; 66 64 67 procedure TMainForm. IntegerListButtonClick(Sender: TObject);65 procedure TMainForm.ButtonIntegerListClick(Sender: TObject); 68 66 var 69 67 List: TGList<Integer>; … … 72 70 begin 73 71 ListViewOutput.Clear; 74 LabelTestName.Caption := 'T GList<Integer>test';72 LabelTestName.Caption := 'TListInteger test'; 75 73 List := TGList<Integer>.Create; 76 74 List2 := TGList<Integer>.Create; … … 87 85 WriteOutput('First', IntToStr(First)); 88 86 WriteOutput('Last', IntToStr(Last)); 87 WriteOutput('IndexOf(7)', IntToStr(IndexOf(7))); 89 88 MoveItems(3, 2, 3); 90 89 WriteOutput('MoveItems(3, 2, 3)', Implode(',', IntToStr)); … … 107 106 end; 108 107 109 procedure TMainForm.MatrixIntegerButtonClick(Sender: TObject); 110 //var 111 // Matrix: TGMatrix<Integer, Integer, Integer>; 112 begin 113 (* ListViewOutput.Clear; 114 LabelTestName.Caption := 'TGMatrix<Integer> test'; 115 Matrix := TGMatrix<Integer, Integer, Integer>.Create; 108 procedure TMainForm.ButtonMatrixIntegerClick(Sender: TObject); 109 var 110 Matrix: TGMatrix<Integer>; 111 I: Integer; 112 begin 113 ListViewOutput.Clear; 114 LabelTestName.Caption := 'TMatrixInteger test'; 115 Matrix := TGMatrix<Integer>.Create; 116 116 with Matrix do try 117 117 Count := CreateIndex(2, 2); … … 127 127 finally 128 128 Free; 129 end; *) 130 end; 131 132 function ObjectToStr(Obj: TObject): string; 133 begin 134 Result := Obj.ClassName; 135 end; 136 137 procedure TMainForm.ListObjectButtonClick(Sender: TObject); 138 var 139 List: TGObjectList<TObject>; 140 I: Integer; 141 begin 142 ListViewOutput.Clear; 143 LabelTestName.Caption := 'TObjectList<TObject> test'; 144 List := TGObjectList<TObject>.Create; 145 with List do try 146 AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create]); 147 WriteOutput('AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create])', Implode(',', ObjectToStr)); 148 Clear; 149 WriteOutput('Clear', Implode(',', ObjectToStr)); 150 for I := 0 to 10 do Add(TObject.Create); 151 WriteOutput('for I := 0 to 10 do Add(TObject.Create)', Implode(',', ObjectToStr)); 152 WriteOutput('Count', IntToStr(Count)); 153 Reverse; 154 WriteOutput('Reverse', Implode(',', ObjectToStr)); 155 MoveItems(3, 2, 3); 156 WriteOutput('MoveItems(3, 2, 3)', Implode(',', ObjectToStr)); 157 finally 158 Free; 159 end; 160 end; 161 162 procedure TMainForm.QueueIntegerButtonClick(Sender: TObject); 163 var 164 Queue: TGQueue<Integer>; 165 begin 166 ListViewOutput.Clear; 167 LabelTestName.Caption := 'TGQueue<Integer> test'; 168 Queue := TGQueue<Integer>.Create; 169 with Queue do try 170 Enqueue(1); 171 Enqueue(2); 172 Enqueue(3); 173 WriteOutput('Enqueue(1),Enqueue(2),Enqueue(3) ', List.Implode(',', IntToStr)); 174 Enqueue(4); 175 WriteOutput('Enqueue(4)', List.Implode(',', IntToStr)); 176 WriteOutput('Dequeued item', IntToStr(Dequeue)); 177 WriteOutput('Dequeue', List.Implode(',', IntToStr)); 178 finally 179 Free; 180 end; 181 end; 182 183 procedure TMainForm.StreamByteButtonClick(Sender: TObject); 184 var 185 Stream: TGStream<Byte>; 129 end; 130 end; 131 132 procedure TMainForm.ButtonStreamByteClick(Sender: TObject); 133 var 134 Stream: TMemoryStreamByte; 186 135 I: Integer; 187 136 ByteArray: array of Byte; … … 189 138 begin 190 139 ListViewOutput.Clear; 191 LabelTestName.Caption := 'T GStream<Byte>test';192 Stream := T GStream<Byte>.Create;140 LabelTestName.Caption := 'TStreamByte test'; 141 Stream := TMemoryStreamByte.Create; 193 142 with Stream do try 194 143 WriteOutput('Size := ', IntToStr(Stream.Size)); … … 218 167 end; 219 168 220 function StringPairToStr(Pair: TGPair<String, String>): string; 169 function ObjectToStr(Obj: TObject): string; 170 begin 171 Result := Obj.ClassName; 172 end; 173 174 procedure TMainForm.ButtonListObjectClick(Sender: TObject); 175 var 176 List: TGListObject<TObject>; 177 I: Integer; 178 begin 179 ListViewOutput.Clear; 180 LabelTestName.Caption := 'TListObject test'; 181 List := TGListObject<TObject>.Create; 182 with List do try 183 AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create]); 184 WriteOutput('AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create])', Implode(',', ObjectToStr)); 185 Clear; 186 WriteOutput('Clear', Implode(',', ObjectToStr)); 187 for I := 0 to 10 do Add(TObject.Create); 188 WriteOutput('for I := 0 to 10 do Add(TObject.Create)', Implode(',', ObjectToStr)); 189 WriteOutput('Count', IntToStr(Count)); 190 Reverse; 191 WriteOutput('Reverse', Implode(',', ObjectToStr)); 192 MoveItems(3, 2, 3); 193 WriteOutput('MoveItems(3, 2, 3)', Implode(',', ObjectToStr)); 194 finally 195 Free; 196 end; 197 end; 198 199 procedure TMainForm.ButtonQueueIntegerClick(Sender: TObject); 200 var 201 Queue: TGQueue<Integer>; 202 I: Integer; 203 begin 204 ListViewOutput.Clear; 205 LabelTestName.Caption := 'TQueueInteger test'; 206 Queue := TGQueue<Integer>.Create; 207 with Queue do try 208 Enqueue(1); 209 Enqueue(2); 210 Enqueue(3); 211 WriteOutput('Enqueue(1),Enqueue(2),Enqueue(3) ', List.Implode(',', IntToStr)); 212 Enqueue(4); 213 WriteOutput('Enqueue(4)', List.Implode(',', IntToStr)); 214 WriteOutput('Dequeued item', IntToStr(Dequeue)); 215 WriteOutput('Dequeue', List.Implode(',', IntToStr)); 216 finally 217 Free; 218 end; 219 end; 220 221 function StringPairToStr(Pair: TGPair<string,string>): string; 221 222 begin 222 223 Result := Pair.Key + ':' + Pair.Value; 223 224 end; 224 225 225 procedure TMainForm.DictionaryStringButtonClick(Sender: TObject); 226 //type 227 // TPairStringString = TGPair<string, string>; 226 procedure TMainForm.ButtonDictionaryStringClick(Sender: TObject); 228 227 var 229 228 Dictionary: TGDictionary<string, string>; 230 229 begin 231 230 ListViewOutput.Clear; 232 LabelTestName.Caption := 'T GDictionary<string, string>test';231 LabelTestName.Caption := 'TDictionaryString test'; 233 232 Dictionary := TGDictionary<string, string>.Create; 234 233 with Dictionary do try … … 241 240 Values['Key2'] := 'None'; 242 241 WriteOutput('Values[Key2]', Values['Key2']); 243 WriteOutput(' Index of Key0', IntToStr(SearchKey('Key0')));242 WriteOutput('Values[Key0]', Values['Key0']); 244 243 WriteOutput('Keys[2]', Keys[2]); 245 244 finally … … 253 252 end; 254 253 255 procedure TMainForm. CharListButtonClick(Sender: TObject);256 var 257 List: T GString<Char>;258 List2: T GString<Char>;259 begin 260 ListViewOutput.Clear; 261 LabelTestName.Caption := 'T GString<Char>test';262 List := T GString<Char>.Create;263 List2 := T GString<Char>.Create;254 procedure TMainForm.ButtonCharListClick(Sender: TObject); 255 var 256 List: TListChar; 257 List2: TListChar; 258 begin 259 ListViewOutput.Clear; 260 LabelTestName.Caption := 'TListChar test'; 261 List := TListChar.Create; 262 List2 := TListChar.Create; 264 263 with List do try 265 264 AddArray([' ', ' ', 'A', 'b', 'c', 'd', ' ']); … … 287 286 procedure TMainForm.ButtonBenchmarkListStringClick(Sender: TObject); 288 287 var 289 List: TGList< String>;288 List: TGList<string>; 290 289 List2: TStringList; 291 290 StartTime: TDateTime; … … 295 294 SampleCount: Integer = 100000; 296 295 begin 297 LabelTestName.Caption := 'Generic specialized T GStringList<string>vs. classic non-generic TStringList benchmark';296 LabelTestName.Caption := 'Generic specialized TListString vs. classic non-generic TStringList benchmark'; 298 297 ListViewOutput.Clear; 299 298 try 300 299 UpdateButtonState(False); 301 List := TGList< String>.Create;300 List := TGList<string>.Create; 302 301 List2 := TStringList.Create; 303 302 … … 306 305 List.Add(SampleText); 307 306 until (Now - StartTime) > MeasureDuration; 308 WriteOutput('T ListString.Add', IntToStr(List.Count) + ' ops');307 WriteOutput('TGList<String>.Add', IntToStr(List.Count) + ' ops'); 309 308 List.Clear; 310 309 Application.ProcessMessages; … … 322 321 List.Insert(0, SampleText); 323 322 until (Now - StartTime) > MeasureDuration; 324 WriteOutput('T ListString.Insert', IntToStr(List.Count) + ' ops');323 WriteOutput('TGList<String>.Insert', IntToStr(List.Count) + ' ops'); 325 324 List.Clear; 326 325 Application.ProcessMessages; … … 342 341 Inc(I); 343 342 until (Now - StartTime) > MeasureDuration; 344 WriteOutput('T ListString.Delete', IntToStr(I) + ' ops');343 WriteOutput('TGList<String>.Delete', IntToStr(I) + ' ops'); 345 344 List.Clear; 346 345 Application.ProcessMessages; … … 365 364 Inc(I); 366 365 until (Now - StartTime) > MeasureDuration; 367 WriteOutput('T ListString.Move', IntToStr(I) + ' ops');366 WriteOutput('TGList<String>.Move', IntToStr(I) + ' ops'); 368 367 List.Clear; 369 368 Application.ProcessMessages; … … 388 387 Inc(I); 389 388 until (Now - StartTime) > MeasureDuration; 390 WriteOutput('T ListString.Exchange', IntToStr(I) + ' ops');389 WriteOutput('TGList<String>.Exchange', IntToStr(I) + ' ops'); 391 390 List.Clear; 392 391 Application.ProcessMessages; … … 411 410 Inc(I); 412 411 until (Now - StartTime) > MeasureDuration; 413 WriteOutput('T ListString.IndexOf', IntToStr(I) + ' ops');412 WriteOutput('TGList<String>.IndexOf', IntToStr(I) + ' ops'); 414 413 List.Clear; 415 414 Application.ProcessMessages; … … 434 433 435 434 procedure TMainForm.ButtonBenchmarkDictionaryClick(Sender: TObject); 436 //type 437 // TPairStringString = TGPair<String, String>; 438 var 439 Dictionary: TGDictionary<string, string>; 435 var 436 Dictionary: TGDictionary<string,string>; 440 437 Dictionary2: TStringList; 441 438 StartTime: TDateTime; … … 443 440 R: string; 444 441 begin 445 LabelTestName.Caption := 'Generic specialized T GDictionary<string,string>vs. classic non-generic TStringList benchmark';442 LabelTestName.Caption := 'Generic specialized TDictionaryStringString vs. classic non-generic TStringList benchmark'; 446 443 ListViewOutput.Clear; 447 444 try 448 445 UpdateButtonState(False); 449 Dictionary := TGDictionary<string, 446 Dictionary := TGDictionary<string,string>.Create; 450 447 Dictionary2 := TStringList.Create; 451 448 Dictionary2.NameValueSeparator := '|'; … … 457 454 I := I + 1; 458 455 until (Now - StartTime) > MeasureDuration; 459 WriteOutput('T DictionaryStringString.Add', IntToStr(Dictionary.List.Count) + ' ops');456 WriteOutput('TGDictionary<string,string>.Add', IntToStr(Dictionary.Count) + ' ops'); 460 457 Application.ProcessMessages; 461 458 … … 472 469 StartTime := Now; 473 470 repeat 474 R := Dictionary.Values[IntToStr(I mod Dictionary. List.Count)];471 R := Dictionary.Values[IntToStr(I mod Dictionary.Count)]; 475 472 I := I + 1; 476 473 until (Now - StartTime) > MeasureDuration; 477 WriteOutput('T DictionaryStringString.Values', IntToStr(I) + ' ops');474 WriteOutput('TGDictionary<string,string>.Values', IntToStr(I) + ' ops'); 478 475 Application.ProcessMessages; 479 476 … … 490 487 StartTime := Now; 491 488 repeat 492 R := Dictionary.Keys[I mod Dictionary. List.Count];489 R := Dictionary.Keys[I mod Dictionary.Count]; 493 490 I := I + 1; 494 491 until (Now - StartTime) > MeasureDuration; 495 WriteOutput('T DictionaryStringString.Keys', IntToStr(I) + ' ops');492 WriteOutput('TGDictionary<string,string>.Keys', IntToStr(I) + ' ops'); 496 493 Application.ProcessMessages; 497 494 … … 508 505 StartTime := Now; 509 506 repeat 510 R := Dictionary.List.Items[I mod Dictionary. List.Count].Value;507 R := Dictionary.List.Items[I mod Dictionary.Count].Value; 511 508 I := I + 1; 512 509 until (Now - StartTime) > MeasureDuration; 513 WriteOutput('T DictionaryStringString.Items', IntToStr(I) + ' ops');510 WriteOutput('TGDictionary<string,string>.Items', IntToStr(I) + ' ops'); 514 511 Application.ProcessMessages; 515 512 … … 534 531 List: TGList<Pointer>; 535 532 List2: TFPList; 533 List3: TFPGList<Pointer>; 534 S: TList; 536 535 StartTime: TDateTime; 537 536 I: Integer; 537 K: Integer; 538 538 const 539 539 SampleCount: Integer = 100000; 540 540 begin 541 LabelTestName.Caption := 'Generic specialized T GObjectList<Object>vs. classic non-generic TFPList benchmark';541 LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TFPList benchmark'; 542 542 ListViewOutput.Clear; 543 543 try … … 545 545 List := TGList<Pointer>.Create; 546 546 List2 := TFPList.Create; 547 548 WriteOutput('TListPointer.InstanceSize', IntToStr(TGList<Pointer>.InstanceSize) + ' bytes'); 547 List3 := TFPGList<Pointer>.Create; 548 549 WriteOutput('TGList<Pointer>.InstanceSize', IntToStr(TGList<Pointer>.InstanceSize) + ' bytes'); 549 550 WriteOutput('TFPList.InstanceSize', IntToStr(TFPList.InstanceSize) + ' bytes'); 551 WriteOutput('TFPGList<Pointer>.InstanceSize', IntToStr(TFPGList<Pointer>.InstanceSize) + ' bytes'); 550 552 551 553 StartTime := Now; … … 553 555 List.Add(Pointer(1)); 554 556 until (Now - StartTime) > MeasureDuration; 555 WriteOutput('T ListPointer.Add', IntToStr(List.Count) + ' ops');557 WriteOutput('TGList<Pointer>.Add', IntToStr(List.Count) + ' ops'); 556 558 List.Clear; 557 559 Application.ProcessMessages; … … 567 569 StartTime := Now; 568 570 repeat 571 List3.Add(Pointer(1)); 572 until (Now - StartTime) > MeasureDuration; 573 WriteOutput('TFPGList<Pointer>.Add', IntToStr(List3.Count) + ' ops'); 574 List3.Clear; 575 Application.ProcessMessages; 576 577 StartTime := Now; 578 repeat 569 579 List.Insert(0, Pointer(1)); 570 580 until (Now - StartTime) > MeasureDuration; 571 WriteOutput('T ListPointer.Insert', IntToStr(List.Count) + ' ops');581 WriteOutput('TGList<Pointer>.Insert', IntToStr(List.Count) + ' ops'); 572 582 List.Clear; 573 583 Application.ProcessMessages; … … 581 591 Application.ProcessMessages; 582 592 593 StartTime := Now; 594 repeat 595 List3.Insert(0, Pointer(1)); 596 until (Now - StartTime) > MeasureDuration; 597 WriteOutput('TFPGList<Pointer>.Insert', IntToStr(List3.Count) + ' ops'); 598 List3.Clear; 599 Application.ProcessMessages; 600 583 601 for I := 0 to SampleCount - 1 do 584 602 List.Add(Pointer(1)); … … 589 607 Inc(I); 590 608 until (Now - StartTime) > MeasureDuration; 591 WriteOutput('T ListPointer.Delete', IntToStr(I) + ' ops');609 WriteOutput('TGList<Pointer>.Delete', IntToStr(I) + ' ops'); 592 610 List.Clear; 593 611 Application.ProcessMessages; … … 605 623 606 624 for I := 0 to SampleCount - 1 do 625 List3.Add(Pointer(1)); 626 StartTime := Now; 627 I := 0; 628 repeat 629 List3.Delete(0); 630 Inc(I); 631 until (Now - StartTime) > MeasureDuration; 632 WriteOutput('TFPGList<Pointer>.Delete', IntToStr(I) + ' ops'); 633 Application.ProcessMessages; 634 635 for I := 0 to SampleCount - 1 do 607 636 List.Add(Pointer(1)); 608 637 StartTime := Now; … … 612 641 Inc(I); 613 642 until (Now - StartTime) > MeasureDuration; 614 WriteOutput('T ListPointer.Move', IntToStr(I) + ' ops');615 List.Clear; 616 Application.ProcessMessages; 617 618 for I := 0 to SampleCount - 1 do 619 List2.Add(Pointer(1));643 WriteOutput('TGList<Pointer>.Move', IntToStr(I) + ' ops'); 644 List.Clear; 645 Application.ProcessMessages; 646 647 for I := 0 to SampleCount - 1 do 648 List2.Add(Pointer(1)); 620 649 StartTime := Now; 621 650 I := 0; … … 628 657 629 658 for I := 0 to SampleCount - 1 do 659 List3.Add(Pointer(1)); 660 StartTime := Now; 661 I := 0; 662 repeat 663 List3.Move(Round(SampleCount * 0.3), Round(SampleCount * 0.7)); 664 Inc(I); 665 until (Now - StartTime) > MeasureDuration; 666 WriteOutput('TFPGList<Pointer>.Move', IntToStr(I) + ' ops'); 667 Application.ProcessMessages; 668 669 for I := 0 to SampleCount - 1 do 630 670 List.Add(Pointer(1)); 631 671 StartTime := Now; … … 635 675 Inc(I); 636 676 until (Now - StartTime) > MeasureDuration; 637 WriteOutput('TListPointer.Exchange', IntToStr(I) + ' ops'); 638 List.Clear; 639 Application.ProcessMessages; 640 641 for I := 0 to SampleCount - 1 do 642 List2.Add(Pointer(1)); 677 WriteOutput('TGList<Pointer>.Exchange', IntToStr(I) + ' ops'); 678 Application.ProcessMessages; 679 680 for I := 0 to SampleCount - 1 do 681 List2.Add(Pointer(1)); 643 682 StartTime := Now; 644 683 I := 0; … … 651 690 652 691 for I := 0 to SampleCount - 1 do 692 List3.Add(Pointer(1)); 693 StartTime := Now; 694 I := 0; 695 repeat 696 List3.Exchange(Round(SampleCount * 0.3), Round(SampleCount * 0.7)); 697 Inc(I); 698 until (Now - StartTime) > MeasureDuration; 699 WriteOutput('TFPGList<Pointer>.Exchange', IntToStr(I) + ' ops'); 700 Application.ProcessMessages; 701 702 for I := 0 to SampleCount - 1 do 703 List.Add(Pointer(I)); 704 StartTime := Now; 705 I := 0; 706 repeat 707 K := List.IndexOf(Pointer(I mod List.Count)); 708 Inc(I); 709 until (Now - StartTime) > MeasureDuration; 710 WriteOutput('TGList<Pointer>.IndexOf', IntToStr(I) + ' ops'); 711 List.Clear; 712 Application.ProcessMessages; 713 714 for I := 0 to SampleCount - 1 do 715 List2.Add(Pointer(I)); 716 StartTime := Now; 717 I := 0; 718 repeat 719 K := List2.IndexOf(Pointer(I mod List2.Count)); 720 Inc(I); 721 until (Now - StartTime) > MeasureDuration; 722 WriteOutput('TFPList.IndexOf', IntToStr(I) + ' ops'); 723 Application.ProcessMessages; 724 725 for I := 0 to SampleCount - 1 do 726 List3.Add(Pointer(I)); 727 StartTime := Now; 728 I := 0; 729 repeat 730 K := List3.IndexOf(Pointer(I mod List3.Count)); 731 Inc(I); 732 until (Now - StartTime) > MeasureDuration; 733 WriteOutput('TFPGList<Pointer>.IndexOf', IntToStr(I) + ' ops'); 734 Application.ProcessMessages; 735 736 for I := 0 to SampleCount - 1 do 653 737 List.Add(Pointer(1)); 654 738 StartTime := Now; 655 739 I := 0; 656 740 repeat 657 List.IndexOf(Pointer(I mod List.Count)); 658 Inc(I); 659 until (Now - StartTime) > MeasureDuration; 660 WriteOutput('TListPointer.IndexOf', IntToStr(I) + ' ops'); 661 List.Clear; 662 Application.ProcessMessages; 663 664 for I := 0 to SampleCount - 1 do 665 List2.Add(Pointer(1)); 666 StartTime := Now; 667 I := 0; 668 repeat 669 List2.IndexOf(Pointer(I mod List2.Count)); 670 Inc(I); 671 until (Now - StartTime) > MeasureDuration; 672 WriteOutput('TFPList.IndexOf', IntToStr(I) + ' ops'); 741 List[I mod List.Count] := Pointer(1); 742 Inc(I); 743 until (Now - StartTime) > MeasureDuration; 744 WriteOutput('TGList<Pointer>[I] write', IntToStr(I) + ' ops'); 745 List.Clear; 746 Application.ProcessMessages; 747 748 for I := 0 to SampleCount - 1 do 749 List2.Add(Pointer(1)); 750 StartTime := Now; 751 I := 0; 752 repeat 753 List2[I mod List2.Count] := Pointer(1); 754 Inc(I); 755 until (Now - StartTime) > MeasureDuration; 756 WriteOutput('TFPList[I] write', IntToStr(I) + ' ops'); 757 Application.ProcessMessages; 758 759 for I := 0 to SampleCount - 1 do 760 List3.Add(Pointer(1)); 761 StartTime := Now; 762 I := 0; 763 repeat 764 List3[I mod List3.Count] := Pointer(1); 765 Inc(I); 766 until (Now - StartTime) > MeasureDuration; 767 WriteOutput('TFPGList<Pointer>[I] write', IntToStr(I) + ' ops'); 673 768 Application.ProcessMessages; 674 769 … … 678 773 I := 0; 679 774 repeat 680 List[I mod List.Count] := Pointer(1);681 Inc(I);682 until (Now - StartTime) > MeasureDuration;683 WriteOutput('TListPointer[I] write', IntToStr(I) + ' ops');684 List.Clear;685 Application.ProcessMessages;686 687 for I := 0 to SampleCount - 1 do688 List2.Add(Pointer(1));689 StartTime := Now;690 I := 0;691 repeat692 List2[I mod List2.Count] := Pointer(1);693 Inc(I);694 until (Now - StartTime) > MeasureDuration;695 WriteOutput('TFPList[I] write', IntToStr(I) + ' ops');696 Application.ProcessMessages;697 698 for I := 0 to SampleCount - 1 do699 List.Add(Pointer(1));700 StartTime := Now;701 I := 0;702 repeat703 775 List[I mod List.Count]; 704 776 Inc(I); 705 777 until (Now - StartTime) > MeasureDuration; 706 WriteOutput('T ListPointer[I] read', IntToStr(I) + ' ops');707 List.Clear; 708 Application.ProcessMessages; 709 710 for I := 0 to SampleCount - 1 do 711 List2.Add(Pointer(1));778 WriteOutput('TGList<Pointer>[I] read', IntToStr(I) + ' ops'); 779 List.Clear; 780 Application.ProcessMessages; 781 782 for I := 0 to SampleCount - 1 do 783 List2.Add(Pointer(1)); 712 784 StartTime := Now; 713 785 I := 0; … … 718 790 WriteOutput('TFPList[I] read', IntToStr(I) + ' ops'); 719 791 Application.ProcessMessages; 792 793 for I := 0 to SampleCount - 1 do 794 List3.Add(Pointer(1)); 795 StartTime := Now; 796 I := 0; 797 repeat 798 List3[I mod List3.Count]; 799 Inc(I); 800 until (Now - StartTime) > MeasureDuration; 801 WriteOutput('TFPGList<Pointer>[I] read', IntToStr(I) + ' ops'); 802 Application.ProcessMessages; 803 720 804 finally 721 805 UpdateButtonState(True); 722 806 List.Free; 723 807 List2.Free; 808 List3.Free; 724 809 end; 725 810 end; … … 730 815 end; 731 816 732 procedure TMainForm. StringListButtonClick(Sender: TObject);733 var 734 List: TGList< String>;735 begin 736 ListViewOutput.Clear; 737 WriteOutput('T GList<string>test');738 List := TGList< String>.Create;817 procedure TMainForm.ButtonStringListClick(Sender: TObject); 818 var 819 List: TGList<string>; 820 begin 821 ListViewOutput.Clear; 822 WriteOutput('TListString test'); 823 List := TGList<string>.Create; 739 824 with List do try 740 825 AddArray(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']); … … 761 846 end; 762 847 763 procedure TMainForm.TreeButtonClick(Sender: TObject);764 var765 //Tree: TGTree<string>;766 //Tree2: TGTree<string>;767 I: Integer;768 begin769 (* ListViewOutput.Clear;770 LabelTestName.Caption := 'TGTree<string> test';771 Tree := TGTree<string>.Create;772 Tree2 := TGTree<string>.Create;773 with Tree do try774 Tree.TopItem.Add('test');775 AddArray([10, 20, 30, 40]);776 WriteOutput('AddArray([10, 20, 30, 40])', Implode(',', IntToStr));777 Clear;778 WriteOutput('Clear', Implode(',', IntToStr));779 for I := 0 to 10 do Add(I);780 WriteOutput('for I := 0 to 10 do Add(I)', Implode(',', IntToStr));781 WriteOutput('Count', IntToStr(Count));782 Reverse;783 WriteOutput('Reverse', Implode(',', IntToStr));784 WriteOutput('First', IntToStr(First));785 WriteOutput('Last', IntToStr(Last));786 MoveItems(3, 2, 3);787 WriteOutput('MoveItems(3, 2, 3)', Implode(',', IntToStr));788 Insert(5, 11);789 WriteOutput('Insert(5, 11)', Implode(',', IntToStr));790 DeleteItems(0, 10);791 WriteOutput('Delete(0, 10)', Implode(',', IntToStr));792 List2.SetArray([1, 0]);793 WriteOutput('EqualTo([6, 11])', BoolToStr(EqualTo(List2)));794 List2.SetArray([2, 0]);795 WriteOutput('EqualTo([7, 11])', BoolToStr(EqualTo(List2)));796 InsertCount(0, 3);797 WriteOutput('InsertCount(0, 3)', Implode(',', IntToStr));798 Fill(0, 3, 9);799 WriteOutput('Fill(0, 3, 9)', Implode(',', IntToStr));800 finally801 Free;802 Tree2.Free;803 end; *)804 end;805 806 848 procedure TMainForm.UpdateButtonState(Enabled: Boolean); 807 849 begin 808 850 ButtonBenchmarkDictionary.Enabled := Enabled; 809 851 ButtonBenchmarkListString.Enabled := Enabled; 810 CharListButton.Enabled := Enabled;811 DictionaryStringButton.Enabled := Enabled;812 IntegerListButton.Enabled := Enabled;813 ListObjectButton.Enabled := Enabled;814 MatrixIntegerButton.Enabled := Enabled;815 QueueIntegerButton.Enabled := Enabled;816 StringListButton.Enabled := Enabled;852 ButtonCharList.Enabled := Enabled; 853 ButtonDictionaryString.Enabled := Enabled; 854 ButtonIntegerList.Enabled := Enabled; 855 ButtonListObject.Enabled := Enabled; 856 ButtonMatrixInteger.Enabled := Enabled; 857 ButtonQueueInteger.Enabled := Enabled; 858 ButtonStringList.Enabled := Enabled; 817 859 end; 818 860
Note:
See TracChangeset
for help on using the changeset viewer.