- Timestamp:
- Jan 3, 2011, 8:23:44 AM (14 years ago)
- Location:
- Generics/TemplateGenerics/Demo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Demo/Demo.lpi
r110 r111 38 38 </Item2> 39 39 </RequiredPackages> 40 <Units Count=" 59">40 <Units Count="62"> 41 41 <Unit0> 42 42 <Filename Value="Demo.lpr"/> … … 55 55 <ResourceBaseClass Value="Form"/> 56 56 <UnitName Value="UMainForm"/> 57 <IsVisibleTab Value="True"/>58 57 <EditorIndex Value="0"/> 59 58 <WindowIndex Value="0"/> 60 <TopLine Value=" 404"/>61 <CursorPos X=" 49" Y="419"/>59 <TopLine Value="232"/> 60 <CursorPos X="19" Y="237"/> 62 61 <UsageCount Value="233"/> 63 62 <Bookmarks Count="1"> 64 <Item0 X="65" Y="22 1" ID="2"/>63 <Item0 X="65" Y="224" ID="2"/> 65 64 </Bookmarks> 66 65 <Loaded Value="True"/> … … 77 76 </Unit2> 78 77 <Unit3> 79 <Filename Value="../Specialized/ specializedlist.pas"/>78 <Filename Value="../Specialized/SpecializedList.pas"/> 80 79 <UnitName Value="SpecializedList"/> 80 <EditorIndex Value="2"/> 81 81 <WindowIndex Value="0"/> 82 82 <TopLine Value="3"/> 83 83 <CursorPos X="43" Y="13"/> 84 <UsageCount Value="4"/> 84 <UsageCount Value="10"/> 85 <Loaded Value="True"/> 85 86 </Unit3> 86 87 <Unit4> … … 311 312 <Unit32> 312 313 <Filename Value="../Generic/GenericList.inc"/> 313 <EditorIndex Value=" 2"/>314 <WindowIndex Value="0"/> 315 <TopLine Value=" 170"/>316 <CursorPos X=" 82" Y="183"/>314 <EditorIndex Value="6"/> 315 <WindowIndex Value="0"/> 316 <TopLine Value="462"/> 317 <CursorPos X="30" Y="470"/> 317 318 <UsageCount Value="107"/> 318 319 <Loaded Value="True"/> … … 417 418 <Unit46> 418 419 <Filename Value="../Generic/GenericMatrix.inc"/> 419 <EditorIndex Value=" 3"/>420 <EditorIndex Value="7"/> 420 421 <WindowIndex Value="0"/> 421 422 <TopLine Value="311"/> … … 493 494 <Filename Value="../Specialized/SpecializedMatrix.pas"/> 494 495 <UnitName Value="SpecializedMatrix"/> 495 <EditorIndex Value=" 4"/>496 <EditorIndex Value="8"/> 496 497 <WindowIndex Value="0"/> 497 498 <TopLine Value="31"/> 498 499 <CursorPos X="38" Y="62"/> 499 <UsageCount Value="1 8"/>500 <UsageCount Value="19"/> 500 501 <Loaded Value="True"/> 501 502 </Unit56> … … 510 511 <Unit58> 511 512 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/dateutil.inc"/> 512 <EditorIndex Value=" 1"/>513 <EditorIndex Value="5"/> 513 514 <WindowIndex Value="0"/> 514 515 <TopLine Value="38"/> 515 516 <CursorPos X="3" Y="50"/> 517 <UsageCount Value="11"/> 518 <Loaded Value="True"/> 519 </Unit58> 520 <Unit59> 521 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 522 <IsVisibleTab Value="True"/> 523 <EditorIndex Value="1"/> 524 <WindowIndex Value="0"/> 525 <TopLine Value="649"/> 526 <CursorPos X="23" Y="661"/> 516 527 <UsageCount Value="10"/> 517 528 <Loaded Value="True"/> 518 </Unit58> 529 </Unit59> 530 <Unit60> 531 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/> 532 <EditorIndex Value="4"/> 533 <WindowIndex Value="0"/> 534 <TopLine Value="1185"/> 535 <CursorPos X="22" Y="1196"/> 536 <UsageCount Value="10"/> 537 <Loaded Value="True"/> 538 </Unit60> 539 <Unit61> 540 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/types.pp"/> 541 <UnitName Value="types"/> 542 <EditorIndex Value="3"/> 543 <WindowIndex Value="0"/> 544 <TopLine Value="112"/> 545 <CursorPos X="3" Y="124"/> 546 <UsageCount Value="10"/> 547 <Loaded Value="True"/> 548 </Unit61> 519 549 </Units> 520 <JumpHistory Count="30" HistoryIndex="2 9">550 <JumpHistory Count="30" HistoryIndex="27"> 521 551 <Position1> 522 <Filename Value=" ../Generic/GenericMatrix.inc"/>523 <Caret Line="4 16" Column="1" TopLine="388"/>552 <Filename Value="UMainForm.pas"/> 553 <Caret Line="42" Column="51" TopLine="20"/> 524 554 </Position1> 525 555 <Position2> 526 <Filename Value=" ../Generic/GenericMatrix.inc"/>527 <Caret Line="4 17" Column="1" TopLine="389"/>556 <Filename Value="UMainForm.pas"/> 557 <Caret Line="458" Column="36" TopLine="440"/> 528 558 </Position2> 529 559 <Position3> 530 <Filename Value=" ../Generic/GenericMatrix.inc"/>531 <Caret Line=" 408" Column="1" TopLine="389"/>560 <Filename Value="UMainForm.pas"/> 561 <Caret Line="7" Column="52" TopLine="1"/> 532 562 </Position3> 533 563 <Position4> 534 <Filename Value=" ../Generic/GenericMatrix.inc"/>535 <Caret Line=" 409" Column="1" TopLine="389"/>564 <Filename Value="UMainForm.pas"/> 565 <Caret Line="526" Column="1" TopLine="502"/> 536 566 </Position4> 537 567 <Position5> 538 <Filename Value=" ../Generic/GenericMatrix.inc"/>539 <Caret Line=" 410" Column="1" TopLine="389"/>568 <Filename Value="UMainForm.pas"/> 569 <Caret Line="32" Column="49" TopLine="27"/> 540 570 </Position5> 541 571 <Position6> 542 <Filename Value=" ../Generic/GenericMatrix.inc"/>543 <Caret Line="41 1" Column="1" TopLine="389"/>572 <Filename Value="UMainForm.pas"/> 573 <Caret Line="416" Column="38" TopLine="312"/> 544 574 </Position6> 545 575 <Position7> 546 <Filename Value=" ../Generic/GenericMatrix.inc"/>547 <Caret Line="41 2" Column="1" TopLine="389"/>576 <Filename Value="UMainForm.pas"/> 577 <Caret Line="417" Column="38" TopLine="393"/> 548 578 </Position7> 549 579 <Position8> 550 <Filename Value=" ../Generic/GenericMatrix.inc"/>551 <Caret Line="41 3" Column="1" TopLine="389"/>580 <Filename Value="UMainForm.pas"/> 581 <Caret Line="418" Column="38" TopLine="394"/> 552 582 </Position8> 553 583 <Position9> 554 <Filename Value=" ../Generic/GenericMatrix.inc"/>555 <Caret Line=" 410" Column="1" TopLine="389"/>584 <Filename Value="UMainForm.pas"/> 585 <Caret Line="241" Column="3" TopLine="234"/> 556 586 </Position9> 557 587 <Position10> 558 <Filename Value=" ../Generic/GenericMatrix.inc"/>559 <Caret Line=" 411" Column="1" TopLine="389"/>588 <Filename Value="UMainForm.pas"/> 589 <Caret Line="377" Column="1" TopLine="361"/> 560 590 </Position10> 561 591 <Position11> 562 <Filename Value=" ../Generic/GenericMatrix.inc"/>563 <Caret Line=" 413" Column="1" TopLine="389"/>592 <Filename Value="UMainForm.pas"/> 593 <Caret Line="617" Column="1" TopLine="593"/> 564 594 </Position11> 565 595 <Position12> 566 <Filename Value=" ../Generic/GenericMatrix.inc"/>567 <Caret Line=" 415" Column="1" TopLine="389"/>596 <Filename Value="UMainForm.pas"/> 597 <Caret Line="260" Column="25" TopLine="230"/> 568 598 </Position12> 569 599 <Position13> 570 <Filename Value=" ../Generic/GenericMatrix.inc"/>571 <Caret Line=" 417" Column="1" TopLine="389"/>600 <Filename Value="UMainForm.pas"/> 601 <Caret Line="246" Column="21" TopLine="233"/> 572 602 </Position13> 573 603 <Position14> 574 604 <Filename Value="UMainForm.pas"/> 575 <Caret Line=" 104" Column="13" TopLine="74"/>605 <Caret Line="364" Column="25" TopLine="358"/> 576 606 </Position14> 577 607 <Position15> 578 608 <Filename Value="UMainForm.pas"/> 579 <Caret Line=" 102" Column="7" TopLine="85"/>609 <Caret Line="596" Column="33" TopLine="586"/> 580 610 </Position15> 581 611 <Position16> 582 612 <Filename Value="UMainForm.pas"/> 583 <Caret Line="2 21" Column="64" TopLine="195"/>613 <Caret Line="237" Column="19" TopLine="232"/> 584 614 </Position16> 585 615 <Position17> 586 <Filename Value=" UMainForm.pas"/>587 <Caret Line=" 220" Column="49" TopLine="203"/>616 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 617 <Caret Line="701" Column="36" TopLine="683"/> 588 618 </Position17> 589 619 <Position18> 590 <Filename Value=" UMainForm.pas"/>591 <Caret Line=" 88" Column="16" TopLine="71"/>620 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 621 <Caret Line="659" Column="27" TopLine="653"/> 592 622 </Position18> 593 623 <Position19> 594 <Filename Value=" UMainForm.pas"/>595 <Caret Line=" 87" Column="1" TopLine="71"/>624 <Filename Value="../Generic/GenericList.inc"/> 625 <Caret Line="468" Column="70" TopLine="462"/> 596 626 </Position19> 597 627 <Position20> 598 <Filename Value=" UMainForm.pas"/>599 <Caret Line=" 217" Column="57" TopLine="200"/>628 <Filename Value="../Generic/GenericList.inc"/> 629 <Caret Line="469" Column="1" TopLine="462"/> 600 630 </Position20> 601 631 <Position21> 602 <Filename Value=" UMainForm.pas"/>603 <Caret Line=" 218" Column="55" TopLine="201"/>632 <Filename Value="../Generic/GenericList.inc"/> 633 <Caret Line="470" Column="1" TopLine="462"/> 604 634 </Position21> 605 635 <Position22> 606 <Filename Value=" UMainForm.pas"/>607 <Caret Line=" 221" Column="69" TopLine="191"/>636 <Filename Value="../Generic/GenericList.inc"/> 637 <Caret Line="471" Column="1" TopLine="462"/> 608 638 </Position22> 609 639 <Position23> 610 <Filename Value=" UMainForm.pas"/>611 <Caret Line=" 359" Column="19" TopLine="350"/>640 <Filename Value="../Generic/GenericList.inc"/> 641 <Caret Line="470" Column="5" TopLine="462"/> 612 642 </Position23> 613 643 <Position24> 614 <Filename Value=" ../Generic/GenericList.inc"/>615 <Caret Line=" 193" Column="31" TopLine="180"/>644 <Filename Value="UMainForm.pas"/> 645 <Caret Line="237" Column="19" TopLine="232"/> 616 646 </Position24> 617 647 <Position25> 618 <Filename Value="../ Generic/GenericList.inc"/>619 <Caret Line=" 184" Column="20" TopLine="170"/>648 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 649 <Caret Line="659" Column="26" TopLine="647"/> 620 650 </Position25> 621 651 <Position26> 622 <Filename Value="../ Generic/GenericList.inc"/>623 <Caret Line="1 84" Column="19" TopLine="170"/>652 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/> 653 <Caret Line="1193" Column="20" TopLine="1185"/> 624 654 </Position26> 625 655 <Position27> 626 <Filename Value=" UMainForm.pas"/>627 <Caret Line=" 42" Column="51" TopLine="20"/>656 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/stringl.inc"/> 657 <Caret Line="1196" Column="22" TopLine="1185"/> 628 658 </Position27> 629 659 <Position28> 630 <Filename Value=" UMainForm.pas"/>631 <Caret Line=" 458" Column="36" TopLine="440"/>660 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 661 <Caret Line="661" Column="23" TopLine="649"/> 632 662 </Position28> 633 663 <Position29> 634 <Filename Value=" UMainForm.pas"/>635 <Caret Line=" 7" Column="52" TopLine="1"/>664 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 665 <Caret Line="657" Column="48" TopLine="644"/> 636 666 </Position29> 637 667 <Position30> 638 <Filename Value=" UMainForm.pas"/>639 <Caret Line=" 526" Column="1" TopLine="502"/>668 <Filename Value="../../../../../Programy/Lazarus/fpc/2.4.3/source/rtl/objpas/classes/classesh.inc"/> 669 <Caret Line="651" Column="3" TopLine="639"/> 640 670 </Position30> 641 671 </JumpHistory> -
Generics/TemplateGenerics/Demo/UMainForm.lfm
r110 r111 56 56 TabOrder = 4 57 57 end 58 object ButtonBenchmarkList : TButton59 Left = 858 object ButtonBenchmarkListString: TButton 59 Left = 10 60 60 Height = 24 61 Top = 4 9161 Top = 456 62 62 Width = 128 63 63 Anchors = [akLeft, akBottom] 64 Caption = ' Benchmark list'65 OnClick = ButtonBenchmarkList Click64 Caption = 'TListString' 65 OnClick = ButtonBenchmarkListStringClick 66 66 TabOrder = 5 67 67 end … … 78 78 Left = 10 79 79 Height = 25 80 Top = 4 5980 Top = 424 81 81 Width = 126 82 82 Anchors = [akLeft, akBottom] 83 Caption = ' Benchmark dictionary'83 Caption = 'TDictionaryStringString' 84 84 OnClick = ButtonBenchmarkDictionaryClick 85 85 TabOrder = 7 … … 121 121 ParentColor = False 122 122 end 123 object Label1: TLabel 124 Left = 10 125 Height = 14 126 Top = 408 127 Width = 62 128 Anchors = [akLeft, akBottom] 129 Caption = 'Benchmarks:' 130 ParentColor = False 131 end 132 object ButtonBenchmarkListPointer: TButton 133 Left = 8 134 Height = 24 135 Top = 488 136 Width = 128 137 Anchors = [akLeft, akBottom] 138 Caption = 'TListPointer' 139 OnClick = ButtonBenchmarkListPointerClick 140 TabOrder = 10 141 end 123 142 end -
Generics/TemplateGenerics/Demo/UMainForm.pas
r110 r111 16 16 TMainForm = class(TForm) 17 17 ButtonBenchmarkDictionary: TButton; 18 ButtonBenchmarkListPointer: TButton; 18 19 ButtonListObject: TButton; 19 ButtonBenchmarkList : TButton;20 ButtonBenchmarkListString: TButton; 20 21 ButtonCharList: TButton; 21 22 ButtonMatrixInteger: TButton; … … 24 25 ButtonIntegerList: TButton; 25 26 ButtonStringList: TButton; 27 Label1: TLabel; 26 28 LabelTestName: TLabel; 27 29 ListViewOutput: TListView; 28 30 procedure ButtonBenchmarkDictionaryClick(Sender: TObject); 29 procedure ButtonBenchmarkListClick(Sender: TObject); 31 procedure ButtonBenchmarkListPointerClick(Sender: TObject); 32 procedure ButtonBenchmarkListStringClick(Sender: TObject); 30 33 procedure ButtonCharListClick(Sender: TObject); 31 34 procedure ButtonDictionaryStringClick(Sender: TObject); … … 229 232 end; 230 233 231 procedure TMainForm.ButtonBenchmarkList Click(Sender: TObject);232 var 233 List: TList Pointer;234 List2: T List;234 procedure TMainForm.ButtonBenchmarkListStringClick(Sender: TObject); 235 var 236 List: TListString; 237 List2: TStringList; 235 238 StartTime: TDateTime; 236 239 I: Integer; 237 begin 238 LabelTestName.Caption := 'Generic specialized TListObject vs. classic non-generic TList benchmark'; 240 const 241 SampleText: string = 'text'; 242 SampleCount: Integer = 100000; 243 begin 244 LabelTestName.Caption := 'Generic specialized TListString vs. classic non-generic TStringList benchmark'; 239 245 ListViewOutput.Clear; 240 246 try 241 247 UpdateButtonState(False); 242 List := TList Pointer.Create;243 List2 := T List.Create;244 245 StartTime := Now; 246 repeat 247 List.Add( 1);248 until (Now - StartTime) > MeasureDuration; 249 WriteOutput('TList Pointer.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('T List.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'); 258 264 List2.Clear; 259 265 Application.ProcessMessages; … … 261 267 StartTime := Now; 262 268 repeat 263 List.Insert(0, 1);264 until (Now - StartTime) > MeasureDuration; 265 WriteOutput('TList Pointer.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('T List.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'); 274 280 List2.Clear; 275 281 Application.ProcessMessages; 276 282 277 for I := 0 to 1000000do278 List.Add( 1);283 for I := 0 to SampleCount - 1 do 284 List.Add(SampleText); 279 285 StartTime := Now; 280 286 I := 0; … … 283 289 Inc(I); 284 290 until (Now - StartTime) > MeasureDuration; 285 WriteOutput('TList Pointer.Delete', IntToStr(I) + ' ops/sec');286 List.Clear; 287 Application.ProcessMessages; 288 289 for I := 0 to 1000000do290 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); 291 297 StartTime := Now; 292 298 I := 0; … … 295 301 Inc(I); 296 302 until (Now - StartTime) > MeasureDuration; 297 WriteOutput('T List.Delete', IntToStr(I) + ' ops/sec');298 Application.ProcessMessages; 299 300 for I := 0 to 1000000do301 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('TList Pointer.Move', IntToStr(I) + ' ops/sec');309 List.Clear; 310 Application.ProcessMessages; 311 312 for I := 0 to 1000000do313 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('T List.Move', IntToStr(I) + ' ops/sec');321 Application.ProcessMessages; 322 323 for I := 0 to 1000000do324 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('TList Pointer.Exchange', IntToStr(I) + ' ops/sec');332 List.Clear; 333 Application.ProcessMessages; 334 335 for I := 0 to 1000000do336 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('T List.Exchange', IntToStr(I) + ' ops/sec');344 Application.ProcessMessages; 345 346 for I := 0 to 1000000do347 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('TList Pointer.IndexOf', IntToStr(I) + ' ops/sec');355 List.Clear; 356 Application.ProcessMessages; 357 358 for I := 0 to 1000000do359 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('T List.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'); 367 373 Application.ProcessMessages; 368 374 … … 396 402 I := I + 1; 397 403 until (Now - StartTime) > MeasureDuration; 398 WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.Count) + ' ops /sec');404 WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.Count) + ' ops'); 399 405 Application.ProcessMessages; 400 406 … … 405 411 I := I + 1; 406 412 until (Now - StartTime) > MeasureDuration; 407 WriteOutput('TStringList.Add', IntToStr(Dictionary2.Count) + ' ops /sec');413 WriteOutput('TStringList.Add', IntToStr(Dictionary2.Count) + ' ops'); 408 414 Application.ProcessMessages; 409 415 … … 414 420 I := I + 1; 415 421 until (Now - StartTime) > MeasureDuration; 416 WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops /sec');422 WriteOutput('TDictionaryStringString.Values', IntToStr(I) + ' ops'); 417 423 Application.ProcessMessages; 418 424 … … 423 429 I := I + 1; 424 430 until (Now - StartTime) > MeasureDuration; 425 WriteOutput('TStringList.Values', IntToStr(I) + ' ops /sec');431 WriteOutput('TStringList.Values', IntToStr(I) + ' ops'); 426 432 Application.ProcessMessages; 427 433 … … 432 438 I := I + 1; 433 439 until (Now - StartTime) > MeasureDuration; 434 WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops /sec');440 WriteOutput('TDictionaryStringString.Keys', IntToStr(I) + ' ops'); 435 441 Application.ProcessMessages; 436 442 … … 441 447 I := I + 1; 442 448 until (Now - StartTime) > MeasureDuration; 443 WriteOutput('TStringList.Keys(Names)', IntToStr(I) + ' ops /sec');449 WriteOutput('TStringList.Keys(Names)', IntToStr(I) + ' ops'); 444 450 Application.ProcessMessages; 445 451 … … 450 456 I := I + 1; 451 457 until (Now - StartTime) > MeasureDuration; 452 WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops /sec');458 WriteOutput('TDictionaryStringString.Items', IntToStr(I) + ' ops'); 453 459 Application.ProcessMessages; 454 460 … … 459 465 I := I + 1; 460 466 until (Now - StartTime) > MeasureDuration; 461 WriteOutput('TStringList.Items(ValueFromIndex)', IntToStr(I) + ' ops /sec');467 WriteOutput('TStringList.Items(ValueFromIndex)', IntToStr(I) + ' ops'); 462 468 Application.ProcessMessages; 463 469 … … 466 472 Dictionary.Free; 467 473 Dictionary2.Free; 474 end; 475 end; 476 477 procedure TMainForm.ButtonBenchmarkListPointerClick(Sender: TObject); 478 var 479 List: TListPointer; 480 List2: TList; 481 StartTime: TDateTime; 482 I: Integer; 483 const 484 SampleCount: Integer = 100000; 485 begin 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; 468 621 end; 469 622 end; … … 504 657 begin 505 658 ButtonBenchmarkDictionary.Enabled := Enabled; 506 ButtonBenchmarkList .Enabled := Enabled;659 ButtonBenchmarkListString.Enabled := Enabled; 507 660 ButtonCharList.Enabled := Enabled; 508 661 ButtonDictionaryString.Enabled := Enabled;
Note:
See TracChangeset
for help on using the changeset viewer.