Changeset 30 for trunk/Components/TemplateGenerics/Demo/UMainForm.pas
- Timestamp:
- Sep 8, 2012, 9:28:39 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 3 3 backup 4 4 tunneler.exe 5 heaptrclog.trc
-
- Property svn:ignore
-
trunk/Components/TemplateGenerics
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
trunk/Components/TemplateGenerics/Demo/UMainForm.pas
r29 r30 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 9 ComCtrls, SpecializedList, SpecializedDictionary, SpecializedQueue, 10 DateUtils, SpecializedMatrix ;10 DateUtils, SpecializedMatrix, SpecializedStream; 11 11 12 12 type … … 15 15 16 16 TMainForm = class(TForm) 17 ButtonStreamByte: TButton; 17 18 ButtonBenchmarkDictionary: TButton; 18 19 ButtonBenchmarkListPointer: TButton; … … 38 39 procedure ButtonQueueIntegerClick(Sender: TObject); 39 40 procedure ButtonStringListClick(Sender: TObject); 41 procedure ButtonStreamByteClick(Sender: TObject); 40 42 procedure FormCreate(Sender: TObject); 41 43 procedure FormDestroy(Sender: TObject); 42 private43 44 public 44 45 MeasureDuration: TDateTime; … … 65 66 var 66 67 List: TListInteger; 68 List2: TListInteger; 67 69 I: Integer; 68 70 begin … … 70 72 LabelTestName.Caption := 'TListInteger test'; 71 73 List := TListInteger.Create; 74 List2 := TListInteger.Create; 72 75 with List do try 73 76 AddArray([10, 20, 30, 40]); … … 86 89 Insert(5, 11); 87 90 WriteOutput('Insert(5, 11)', Implode(',', IntToStr)); 91 DeleteItems(0, 10); 92 WriteOutput('Delete(0, 10)', Implode(',', IntToStr)); 93 List2.SetArray([1, 0]); 94 WriteOutput('EqualTo([6, 11])', BoolToStr(EqualTo(List2))); 95 List2.SetArray([2, 0]); 96 WriteOutput('EqualTo([7, 11])', BoolToStr(EqualTo(List2))); 97 InsertCount(0, 3); 98 WriteOutput('InsertCount(0, 3)', Implode(',', IntToStr)); 99 Fill(0, 3, 9); 100 WriteOutput('Fill(0, 3, 9)', Implode(',', IntToStr)); 88 101 finally 89 102 Free; 103 List2.Free; 90 104 end; 91 105 end; … … 110 124 WriteOutput('Clear', '[' + Implode('; ', ', ', IntToStr) + ']'); 111 125 WriteOutput('Count [Y, X]', IntToStr(Count.Y) + ', ' + IntToStr(Count.X)); 126 finally 127 Free; 128 end; 129 end; 130 131 procedure TMainForm.ButtonStreamByteClick(Sender: TObject); 132 var 133 Stream: TMemoryStreamByte; 134 I: Integer; 135 ByteArray: array of Byte; 136 ByteArrayText: string; 137 begin 138 ListViewOutput.Clear; 139 LabelTestName.Caption := 'TStreamByte test'; 140 Stream := TMemoryStreamByte.Create; 141 with Stream do try 142 WriteOutput('Size := ', IntToStr(Stream.Size)); 143 Write(1); 144 WriteOutput('Write(1)', ''); 145 WriteOutput('Size, Position', IntToStr(Stream.Size) + ', ' + IntToStr(Stream.Position)); 146 WriteArray([2, 3, 4]); 147 WriteOutput('WriteArray([2, 3, 4])', ''); 148 WriteOutput('Size, Position', IntToStr(Stream.Size) + ', ' + IntToStr(Stream.Position)); 149 Position := 1; 150 WriteOutput('Position := 1', ''); 151 WriteOutput('Size, Position', IntToStr(Stream.Size) + ', ' + IntToStr(Stream.Position)); 152 WriteOutput('Read', IntToStr(Read)); 153 WriteOutput('Size, Position', IntToStr(Stream.Size) + ', ' + IntToStr(Stream.Position)); 154 ByteArray := ReadArray(2); 155 ByteArrayText := '['; 156 for I := 0 to Length(ByteArray) - 1 do begin 157 ByteArrayText := ByteArrayText + IntToStr(ByteArray[I]); 158 if I < Length(ByteArray) - 1 then ByteArrayText := ByteArrayText + ', '; 159 end; 160 ByteArrayText := ByteArrayText + ']'; 161 WriteOutput('ReadArray', ByteArrayText); 162 WriteOutput('Size, Position', IntToStr(Stream.Size) + ', ' + IntToStr(Stream.Position)); 112 163 finally 113 164 Free; … … 478 529 var 479 530 List: TListPointer; 480 List2: T List;531 List2: TFPList; 481 532 StartTime: TDateTime; 482 533 I: Integer; … … 484 535 SampleCount: Integer = 100000; 485 536 begin 486 LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic T List benchmark';537 LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TFPList benchmark'; 487 538 ListViewOutput.Clear; 488 539 try 489 540 UpdateButtonState(False); 490 541 List := TListPointer.Create; 491 List2 := TList.Create; 492 493 StartTime := Now; 494 repeat 495 List.Add(1); 542 List2 := TFPList.Create; 543 544 WriteOutput('TListPointer.InstanceSize', IntToStr(TListPointer.InstanceSize) + ' bytes'); 545 WriteOutput('TFPList.InstanceSize', IntToStr(TFPList.InstanceSize) + ' bytes'); 546 547 StartTime := Now; 548 repeat 549 List.Add(Pointer(1)); 496 550 until (Now - StartTime) > MeasureDuration; 497 551 WriteOutput('TListPointer.Add', IntToStr(List.Count) + ' ops'); … … 501 555 StartTime := Now; 502 556 repeat 503 List2.Add( 1);504 until (Now - StartTime) > MeasureDuration; 505 WriteOutput('T List.Add', IntToStr(List2.Count) + ' ops');557 List2.Add(Pointer(1)); 558 until (Now - StartTime) > MeasureDuration; 559 WriteOutput('TFPList.Add', IntToStr(List2.Count) + ' ops'); 506 560 List2.Clear; 507 561 Application.ProcessMessages; … … 509 563 StartTime := Now; 510 564 repeat 511 List.Insert(0, 1);565 List.Insert(0, Pointer(1)); 512 566 until (Now - StartTime) > MeasureDuration; 513 567 WriteOutput('TListPointer.Insert', IntToStr(List.Count) + ' ops'); … … 517 571 StartTime := Now; 518 572 repeat 519 List2.Insert(0, 1);520 until (Now - StartTime) > MeasureDuration; 521 WriteOutput('T List.Insert', IntToStr(List2.Count) + ' ops');573 List2.Insert(0, Pointer(1)); 574 until (Now - StartTime) > MeasureDuration; 575 WriteOutput('TFPList.Insert', IntToStr(List2.Count) + ' ops'); 522 576 List2.Clear; 523 577 Application.ProcessMessages; 524 578 525 579 for I := 0 to SampleCount - 1 do 526 List.Add( 1);580 List.Add(Pointer(1)); 527 581 StartTime := Now; 528 582 I := 0; … … 536 590 537 591 for I := 0 to SampleCount - 1 do 538 List2.Add( 1);592 List2.Add(Pointer(1)); 539 593 StartTime := Now; 540 594 I := 0; … … 543 597 Inc(I); 544 598 until (Now - StartTime) > MeasureDuration; 545 WriteOutput('T List.Delete', IntToStr(I) + ' ops');546 Application.ProcessMessages; 547 548 for I := 0 to SampleCount - 1 do 549 List.Add( 1);599 WriteOutput('TFPList.Delete', IntToStr(I) + ' ops'); 600 Application.ProcessMessages; 601 602 for I := 0 to SampleCount - 1 do 603 List.Add(Pointer(1)); 550 604 StartTime := Now; 551 605 I := 0; … … 559 613 560 614 for I := 0 to SampleCount - 1 do 561 List2.Add( 1);615 List2.Add(Pointer(1)); 562 616 StartTime := Now; 563 617 I := 0; … … 566 620 Inc(I); 567 621 until (Now - StartTime) > MeasureDuration; 568 WriteOutput('T List.Move', IntToStr(I) + ' ops');569 Application.ProcessMessages; 570 571 for I := 0 to SampleCount - 1 do 572 List.Add( 1);622 WriteOutput('TFPList.Move', IntToStr(I) + ' ops'); 623 Application.ProcessMessages; 624 625 for I := 0 to SampleCount - 1 do 626 List.Add(Pointer(1)); 573 627 StartTime := Now; 574 628 I := 0; … … 582 636 583 637 for I := 0 to SampleCount - 1 do 584 List2.Add( 1);638 List2.Add(Pointer(1)); 585 639 StartTime := Now; 586 640 I := 0; … … 589 643 Inc(I); 590 644 until (Now - StartTime) > MeasureDuration; 591 WriteOutput('T List.Exchange', IntToStr(I) + ' ops');592 Application.ProcessMessages; 593 594 for I := 0 to SampleCount - 1 do 595 List.Add( 1);645 WriteOutput('TFPList.Exchange', IntToStr(I) + ' ops'); 646 Application.ProcessMessages; 647 648 for I := 0 to SampleCount - 1 do 649 List.Add(Pointer(1)); 596 650 StartTime := Now; 597 651 I := 0; … … 605 659 606 660 for I := 0 to SampleCount - 1 do 607 List2.Add( 1);661 List2.Add(Pointer(1)); 608 662 StartTime := Now; 609 663 I := 0; … … 612 666 Inc(I); 613 667 until (Now - StartTime) > MeasureDuration; 614 WriteOutput('TList.IndexOf', IntToStr(I) + ' ops'); 615 Application.ProcessMessages; 616 668 WriteOutput('TFPList.IndexOf', IntToStr(I) + ' ops'); 669 Application.ProcessMessages; 670 671 for I := 0 to SampleCount - 1 do 672 List.Add(Pointer(1)); 673 StartTime := Now; 674 I := 0; 675 repeat 676 List[I mod List.Count] := Pointer(1); 677 Inc(I); 678 until (Now - StartTime) > MeasureDuration; 679 WriteOutput('TListPointer[I] write', IntToStr(I) + ' ops'); 680 List.Clear; 681 Application.ProcessMessages; 682 683 for I := 0 to SampleCount - 1 do 684 List2.Add(Pointer(1)); 685 StartTime := Now; 686 I := 0; 687 repeat 688 List2[I mod List2.Count] := Pointer(1); 689 Inc(I); 690 until (Now - StartTime) > MeasureDuration; 691 WriteOutput('TFPList[I] write', IntToStr(I) + ' ops'); 692 Application.ProcessMessages; 693 694 for I := 0 to SampleCount - 1 do 695 List.Add(Pointer(1)); 696 StartTime := Now; 697 I := 0; 698 repeat 699 List[I mod List.Count]; 700 Inc(I); 701 until (Now - StartTime) > MeasureDuration; 702 WriteOutput('TListPointer[I] read', IntToStr(I) + ' ops'); 703 List.Clear; 704 Application.ProcessMessages; 705 706 for I := 0 to SampleCount - 1 do 707 List2.Add(Pointer(1)); 708 StartTime := Now; 709 I := 0; 710 repeat 711 List2[I mod List2.Count]; 712 Inc(I); 713 until (Now - StartTime) > MeasureDuration; 714 WriteOutput('TFPList[I] read', IntToStr(I) + ' ops'); 715 Application.ProcessMessages; 617 716 finally 618 717 UpdateButtonState(True); … … 645 744 MoveItems(2, 3, 3); 646 745 WriteOutput('Implode', Implode(',', StrToStr)); 746 InsertCount(0, 3); 747 WriteOutput('InsertCount(0, 3)', Implode(',', StrToStr)); 748 Fill(0, 3, 'Zero'); 749 WriteOutput('Fill(0, 3, ''Zero'')', Implode(',', StrToStr)); 647 750 finally 648 751 Free;
Note:
See TracChangeset
for help on using the changeset viewer.