Changeset 111 for Generics/TemplateGenerics/Demo/UMainForm.pas
- Timestamp:
- Jan 3, 2011, 8:23:44 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.