Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#14

AW: RTTI: generische TObjectList erkennen

  Alt 4. Nov 2021, 09:44
Da messe ich mit Hausmitteln mit D10.4 auf einen i5-7600 in Debug Win32 anderes:

Code:
RTL-Getter -> sum: 5000000050000000 calculated in 205,2559 ms
RTL-list ->  sum: 5000000050000000 calculated in 192,9382 ms
----------------
RTL-Getter -> sum: 5000000050000000 calculated in 204,5107 ms
RTL-list ->  sum: 5000000050000000 calculated in 191,9137 ms
----------------
RTL-Getter -> sum: 5000000050000000 calculated in 205,1316 ms
RTL-list ->  sum: 5000000050000000 calculated in 191,7222 ms
----------------
Delphi-Quellcode:
program Project6;

{$APPTYPE CONSOLE}

{$R *.res}


uses
    System.SysUtils,
    System.Diagnostics,
    Generics.Collections;

const
    cCount: Integer = 100000000;

var
    W: TStopwatch;

procedure RTLGetter;
var
    list: TList<Integer>;
    count, i: Integer;
    sum: Int64;
begin
    list := TList<Integer>.Create;
    count := cCount;
    for i := 1 to count do
        list.Add(i);

    sum := 0;

    W := TStopwatch.StartNew;
    for i := 0 to list.Count - 1 do
        Inc(sum, list[i]);
    W.Stop;

    Writeln('RTL-Getter -> ','sum: ', sum, ' calculated in ', W.Elapsed.TotalMilliseconds.ToString, ' ms');
    list.Free;
end;

procedure RTLList;
var
    list: TList<Integer>;
    count, i: Integer;
    sum: int64;
begin
    list := TList<Integer>.Create;
    count := cCount;
    for i := 1 to count do
        list.Add(i);

    sum := 0;

    W := TStopwatch.StartNew;
    for i := 0 to list.Count - 1 do
        Inc(sum, list.List[i]);
    W.Stop;

    Writeln('RTL-list -> ', 'sum: ', sum, ' calculated in ', W.Elapsed.TotalMilliseconds.ToString, ' ms');
    list.Free;
end;

procedure Benchmark_Main();
begin
    RTLList;
    RTLGetter;
    Writeln('----------------');
end;

begin
    try
        for var I := 1 to 3 do
            Benchmark_Main();
    except
        on E: Exception do
            Writeln(E.ClassName, ': ', E.Message);
    end;
    Readln;

end.
Richtig spannend wird's aber mit Release Win64, da muss ich mal in mich gehen und drüber nachdenken warum das sich so eklatant umkehrt.
Code:
RTL-Getter -> sum: 5000000050000000 calculated in 65,1854 ms
RTL-list ->  sum: 5000000050000000 calculated in 108,6827 ms
----------------
RTL-Getter -> sum: 5000000050000000 calculated in 58,9665 ms
RTL-list ->  sum: 5000000050000000 calculated in 108,7423 ms
----------------
RTL-Getter -> sum: 5000000050000000 calculated in 60,7217 ms
RTL-list ->  sum: 5000000050000000 calculated in 105,2705 ms
----------------

Geändert von TiGü ( 4. Nov 2021 um 09:51 Uhr)
  Mit Zitat antworten Zitat