Anbei mal ein kleines Testprogramm.
Keine Debug-Infos, keine Rangechecks (alles abgeschaltet)
Code: Alles auswählen
program Project1;
{$mode objfpc}
Uses Sysutils;
Var
i:Cardinal;
t:Uint64;
begin
t:=GetTickCount64;
For i:=1 To 1000000000 Do Begin end;
Writeln('For-Loop = ',GetTickCount64-t,' ms');
i:=1; //Reset
t:=GetTickCount64;
While i<=1000000000 Do Begin Inc(i); End;
Writeln('While-Loop = ',GetTickCount64-t,' ms');
i:=1; //Reset
t:=GetTickCount64;
Repeat Inc(i); until i>1000000000;
Writeln('Repeat-Loop = ',GetTickCount64-t,' ms');
Readln;
end.
Meine Maschine Win10-64Bit - Laz2.2.2/FPC3.2.2 - 32 Bit
Für gar keine Optimierung (-O0)
For-Loop = 1672 ms
While-Loop = 1719 ms
Repeat-Loop = 1562 ms
Stufe 1 (-O1)
For-Loop = 1375 ms
While-Loop = 1610 ms
Repeat-Loop = 1875 ms
Stufe 2 (-O2)
For-Loop = 625 ms
While-Loop = 328 ms
Repeat-Loop = 625 ms
Stufe 3 (-O3)
For-Loop = 641 ms
While-Loop = 328 ms
Repeat-Loop = 641 ms
Interessante Ergebnisse.
Zumal der For-Loop eigentlich gar keinen Payload in der Schleife hat