Online
Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.287 Beiträge
Delphi 12 Athens
|
AW: Laufzeitoptimierung eines Consolen-Programms
10. Sep 2023, 13:01
Zitat:
c0= 57 50566 43447 60038 53067 99735 15630 12109 46649 52824 48201 52535 84348 94819 55396 15650
ad=83884813 su=25000001 in 11.24300002 sec
Programmende mit ENTER
* OK, in einem Delphi 7
* mit Codes, die für eine 17 Jahre alte CPU optimiert wurden
* auf einem, 12th Gen Intel Core i7-1260 P 2.10 GHz
* und außerdem wurde es nicht direkt für so "einfache" Berechnungen ausgelegt, sondern auf Cryptography und hochkompliziertes Zeugs, wie 'ne Million Stellen von Pi zu berechnen
Delphi-Quellcode:
program DECMathTest;
{$APPTYPE CONSOLE}
uses
SysUtils,
{ASN1, Console, ConsoleForm, CPU, CRC,
DECCipher, DECData, DECFmt, DECHash, DECRandom, DECUtil,
IDPrimes, IsPrimeHRUnit, LHSZ, NCombi, NGFPBld, NGFPs, NGFPTab,
NIntM,} NInts {NInt_1, NMath, NPolys, NRats, Prime};
{$R *.res}
var
a, b, c, soll, z, sub: IInteger;
start: TDateTime;
duration: Double;
nad, nsu: Int64;
nn: Integer;
begin
NSet(a, '170141183460469231731687303715884105757');
NSet(b, '170141183460469231731687303715884105703');
NSet(soll, '57896044618658097711785492504343953926634992332820282019728792003956564819968');
NSet(z, '340282366920938463463374607431768211455');
NSet(sub, '11111111111111111111111111111111111111111111111111111111111111111111111111111');
nad := 0;
nsu := 0;
start := Now;
for nn := 0 to 25000000 do begin
NMul(c, a, b);
while NCmp(c, soll) < 0 do begin
NAdd(c, c, sub);
Inc(nad);
end;
while NCmp(c, soll) > 0 do begin
NSub(c, c, sub);
Inc(nsu);
end;
NShr(a, c, 128);
NAnd(b, c, z);
end;
duration := (Now - start) * SecsPerDay;
WriteLn('c0=', NStr(c));
WriteLn('ad=', nad, ' su=', nsu, ' in ', duration:1:8, ' sec');
WriteLn;
WriteLn('Programmende mit ENTER');
ReadLn;
end.
Delphi-Quellcode:
for var nn := 25000000 downto 0 do begin
c := a * b;
while c < soll do begin
c := c + sub;
Inc(nad);
end;
while c > soll do begin
c := c - sub;
Inc(nsu);
end;
//a := c div d; //a := c shr 128;
//b := c mod d; //b := c and z;
//MatheString.MatheObj.QuotientModulo(c, d, PString(@a)^, PString(@b)^);
var i := Length(c) - 38;
a := Copy(c, 1, i);
b := Copy(c, i + 1);
end;
Komisch, hätte gedacht, dass das SHR/AND ... ähhh, ich meinte der DIV/MOD-Ersatz, das Tempo enorm runterzieht,
aber ein halbwegs equivalentes DezimalShift senkt die Zeit in meinem StringMath von 9610 auf nur 3355 Sekunden.
Ein Therapeut entspricht 1024 Gigapeut.
Geändert von himitsu (11. Sep 2023 um 11:09 Uhr)
|