Recent

Author Topic: FCL-STL TVector vs Generics.Collections TList append benchmark  (Read 4097 times)

k1ng

  • New Member
  • *
  • Posts: 37
Re: FCL-STL TVector vs Generics.Collections TList append benchmark
« Reply #30 on: August 04, 2019, 05:43:37 pm »
Your code is a complete different mode, so I guess it's not comparable at all with the previous posted codes.
Due to the fact that RTL is compiled in OBJFPC mode, it is more logical to test it in the same mode.
But the initial post uses $mode Delphi, so I'm sure he did that because he needs Delphi compatibility as most people do.


Delphi 10.3.2 - 32bit
Code: Text  [Select][+][-]
  1. List    populated - 100000 keys in 0 ticks.
  2. List    populated - 1000000 keys in 0 ticks.
  3. List    populated - 10000000 keys in 47 ticks.
  4. List    populated - 100000000 keys in 438 ticks.
  5. -- out of memory for last combo
Delphi 10.3.2 - 64bit
Code: Text  [Select][+][-]
  1. List    populated - 100000 keys in 0 ticks.
  2. List    populated - 1000000 keys in 0 ticks.
  3. List    populated - 10000000 keys in 47 ticks.
  4. List    populated - 100000000 keys in 453 ticks.
  5. List    populated - 500000000 keys in 2328 ticks.

ported code to work in Delphi:
Code: Pascal  [Select][+][-]
  1. program fclvsgc;
  2.  
  3. {$apptype CONSOLE}
  4.  
  5. uses
  6.   SysUtils, Classes, windows,
  7.   Generics.Defaults, Generics.Collections;
  8.  
  9. type
  10.   TData = array of Integer;
  11.  
  12. var
  13.   scl: Generics.Collections.TList<LongInt>;
  14.   i: LongInt;
  15.   cnt: LongInt;
  16.   start: UInt64;
  17.  
  18. function GenData(s: LongInt): TData;
  19. var
  20.   I: Integer;
  21. begin
  22.   SetLength(Result, s);
  23.   for I := 0 to High(Result) do
  24.     Result[I] := Random(2147483647);
  25. end;
  26.  
  27. procedure PopulateList(s: LongInt);
  28. var
  29.   Data: TData;
  30. begin
  31.   Data := GenData(s);
  32.   scl := Generics.Collections.TList<LongInt>.Create;
  33.   scl.Capacity := s;
  34.   start := GetTickCount64();
  35.   for i in Data do
  36.     scl.Add(i);
  37.   WriteLn('List    populated - ', s, ' keys in ', GetTickCount64() - start, ' ticks.');
  38.   FreeAndNil(scl);
  39. end;
  40.  
  41. begin
  42.   cnt := 100000;
  43.   PopulateList(cnt);
  44.  
  45.   cnt := 10*cnt;
  46.   PopulateList(cnt);
  47.  
  48.   cnt := 10*cnt;
  49.   PopulateList(cnt);
  50.  
  51.   cnt := 10*cnt;
  52.   PopulateList(cnt);
  53.  
  54.   cnt := 5*cnt;
  55.   PopulateList(cnt);
  56.  
  57.   WriteLn('End.');
  58.   readln;
  59. end.
« Last Edit: August 04, 2019, 05:49:10 pm by k1ng »

julkas

  • Guest
Re: FCL-STL TVector vs Generics.Collections TList append benchmark
« Reply #31 on: August 04, 2019, 05:51:27 pm »
Your code is a complete different mode, so I guess it's not comparable at all with the previous posted codes.
Due to the fact that RTL is compiled in OBJFPC mode, it is more logical to test it in the same mode.
But the initial post uses $mode Delphi, so I'm sure he did that because he needs Delphi compatibility as most people do.


Delphi 10.3.2 - 32bit
Code: Text  [Select][+][-]
  1. List    populated - 100000 keys in 0 ticks.
  2. List    populated - 1000000 keys in 0 ticks.
  3. List    populated - 10000000 keys in 47 ticks.
  4. List    populated - 100000000 keys in 438 ticks.
  5. -- out of memory for last combo
Delphi 10.3.2 - 64bit
Code: Text  [Select][+][-]
  1. List    populated - 100000 keys in 0 ticks.
  2. List    populated - 1000000 keys in 0 ticks.
  3. List    populated - 10000000 keys in 47 ticks.
  4. List    populated - 100000000 keys in 453 ticks.
  5. List    populated - 500000000 keys in 2328 ticks.

ported code to work in Delphi:
Code: Pascal  [Select][+][-]
  1. program fclvsgc;
  2.  
  3. {$apptype CONSOLE}
  4.  
  5. uses
  6.   SysUtils, Classes, windows,
  7.   Generics.Defaults, Generics.Collections;
  8.  
  9. type
  10.   TData = array of Integer;
  11.  
  12. var
  13.   scl: Generics.Collections.TList<LongInt>;
  14.   i: LongInt;
  15.   cnt: LongInt;
  16.   start: UInt64;
  17.  
  18. function GenData(s: LongInt): TData;
  19. var
  20.   I: Integer;
  21. begin
  22.   SetLength(Result, s);
  23.   for I := 0 to High(Result) do
  24.     Result[I] := Random(2147483647);
  25. end;
  26.  
  27. procedure PopulateList(s: LongInt);
  28. var
  29.   Data: TData;
  30. begin
  31.   Data := GenData(s);
  32.   scl := Generics.Collections.TList<LongInt>.Create;
  33.   scl.Capacity := s;
  34.   start := GetTickCount64();
  35.   for i in Data do
  36.     scl.Add(i);
  37.   WriteLn('List    populated - ', s, ' keys in ', GetTickCount64() - start, ' ticks.');
  38.   FreeAndNil(scl);
  39. end;
  40.  
  41. begin
  42.   cnt := 100000;
  43.   PopulateList(cnt);
  44.  
  45.   cnt := 10*cnt;
  46.   PopulateList(cnt);
  47.  
  48.   cnt := 10*cnt;
  49.   PopulateList(cnt);
  50.  
  51.   cnt := 10*cnt;
  52.   PopulateList(cnt);
  53.  
  54.   cnt := 5*cnt;
  55.   PopulateList(cnt);
  56.  
  57.   WriteLn('End.');
  58.   readln;
  59. end.
@k1ng +1.

avk

  • Hero Member
  • *****
  • Posts: 752
Re: FCL-STL TVector vs Generics.Collections TList append benchmark
« Reply #32 on: August 04, 2019, 06:59:22 pm »
...FPC 3.3.1 rev 42572...
@ASerge, thanks, I see this.
And I just found out that on the way from 3.0.4 to 3.3.1 TVector got some dubious improvements.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: FCL-STL TVector vs Generics.Collections TList append benchmark
« Reply #33 on: August 04, 2019, 08:25:54 pm »
Any Delphi (Community) vs FP Generics.Collections bench, test?
This code:
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC}
  2.   {$MODE DELPHI}
  3. {$ENDIF}
  4. {$APPTYPE CONSOLE}
  5.  
  6. uses
  7.   Windows, SysUtils, Generics.Collections;
  8.  
  9. type
  10.   TLongIntList = TList<LongInt>;
  11.   TLongIntArray = TArray<LongInt>;
  12.   TData = TLongIntArray;
  13.  
  14.   TMeasureProc = procedure(const Data: TData);
  15.  
  16. procedure Measure(const Desc: string; Proc: TMeasureProc; const Data: TData);
  17. var
  18.   Start, Elapsed: UInt64;
  19. begin
  20.   Start := GetTickCount64;
  21.   Proc(Data);
  22.   Elapsed := GetTickCount64 - Start;
  23.   Writeln(Desc, 'in ', Elapsed, ' ticks.');
  24. end;
  25.  
  26. function GenData(Count: NativeInt): TData;
  27. var
  28.   i: NativeInt;
  29. begin
  30.   SetLength(Result, Count);
  31.   for i := 0 to High(Result) do
  32.     Result[i] := Random(MaxLongInt);
  33. end;
  34.  
  35. procedure PopulateList(const Data: TData);
  36. var
  37.   List: TLongIntList;
  38.   N: LongInt;
  39. begin
  40.   List := TLongIntList.Create;
  41.   try
  42. //    List.Capacity := Length(Data);
  43.     for N in Data do
  44.       List.Add(N);
  45.   finally
  46.     List.Free;
  47.   end;
  48. end;
  49.  
  50. procedure PopulateArray(const Data: TData);
  51. var
  52.   A: TLongIntArray;
  53.   i: NativeInt;
  54. begin
  55.   SetLength(A, Length(Data));
  56.   for i := Low(Data) to High(Data) do
  57.     A[i] := Data[i]
  58. end;
  59.  
  60. var
  61.   Count: LongInt = Round(1E6);
  62.   Data: TData;
  63. begin
  64.   repeat
  65.     Count := Count * 3;
  66.     Data := GenData(Count);
  67.     Writeln('Populating ', Length(Data), ' keys...');
  68. //    Measure('    Array  ', @PopulateArray, Data);
  69.     Measure('    List   ', PopulateList, Data);
  70.   until Count >= MaxLongInt div 16;
  71.   WriteLn('End.');
  72.   ReadLn;
  73. end.

Delphi Community 10.3 x64 (Optimization on):
Code: Text  [Select][+][-]
  1. Populating 3000000 keys...
  2.     List   in 47 ticks.
  3. Populating 9000000 keys...
  4.     List   in 124 ticks.
  5. Populating 27000000 keys...
  6.     List   in 343 ticks.
  7. Populating 81000000 keys...
  8.     List   in 1139 ticks.
  9. Populating 243000000 keys...
  10.     List   in 3167 ticks.
  11. End.

FPC 3.1.1 x64 (Optimization level 3)
Code: Text  [Select][+][-]
  1. Populating 3000000 keys...
  2.     List   in 78 ticks.
  3. Populating 9000000 keys...
  4.     List   in 203 ticks.
  5. Populating 27000000 keys...
  6.     List   in 624 ticks.
  7. Populating 81000000 keys...
  8.     List   in 1732 ticks.
  9. Populating 243000000 keys...
  10.     List   in 5336 ticks.
  11. End.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: FCL-STL TVector vs Generics.Collections TList append benchmark
« Reply #34 on: August 05, 2019, 09:27:26 am »
Your code is a complete different mode, so I guess it's not comparable at all with the previous posted codes.
Due to the fact that RTL is compiled in OBJFPC mode, it is more logical to test it in the same mode.
That should only matter for parsing not for the generated code (with very small exceptions regarding type conversions and such).

 

TinyPortal © 2005-2018