Digit fifth powers: Difference between revisions

m
→‎{{header|Pascal}}: checking runtime like C++. Restricted to RDTSC on x86-CPU. ~ 523 µs for Power 5.
(→‎{{header|C++}}: exchanged autos for ints)
m (→‎{{header|Pascal}}: checking runtime like C++. Restricted to RDTSC on x86-CPU. ~ 523 µs for Power 5.)
Line 488:
Total: 443839</pre>
=={{header|Pascal}}==
slightly modified [[Own_digits_power_sum]] checks decimals up to power 19.
<lang pascal>program PowerOwnDigits2;
{$IFDEF FPC}
Line 498:
uses
SysUtils,StrUtils;
const
 
CPU_hz = 1000*1000*1000;
const
MAXBASE = 10;
Line 516 ⟶ 517:
Numbers : array of Uint64;
rec_cnt : NativeInt;
 
function GetCPU_Time: Uint64;
type
TCpu = record
HiCpu,
LoCpu : Dword;
end;
var
Cput : TCpu;
begin
{$ASMMODE INTEL}
asm
RDTSC;
MOV Dword Ptr [CpuT.LoCpu],EAX; MOV Dword Ptr [CpuT.HiCpu],EDX
end;
with Cput do result := Uint64(HiCPU) shl 32 + LoCpu;
end;
 
function InitCombIdx(ElemCount: Byte): pbyte;
Line 631 ⟶ 649:
var
digits : pByte;
T0,T1 : Int64UInt64;
tmp : Uint64;
Pot,dgtCnt,i, j : Int32;
 
begin
T0 := GetCPU_Time;
For pot := 2 to MaxDgtCount do
begin
Write('Exponent : ',Pot,' used ');
T1 := GetCPU_Time;
digits := Init(MaxDgtCount,pot);
T0 := GetTickCount64;
rec_cnt := 0;
// i > 0
Line 651 ⟶ 670:
until NextCombWithRep(digits,@gblUD,MaxDgtVal,dgtCnt);
end;
writeln(rec_cnt,' recursions in ',(GetCPU_Time-T1)/CPU_hz:0:6,' GigaCyles');
T0 := GetTickCount64-T0;
writeln(rec_cnt,' recursions');
If length(numbers) > 0 then
Begin
Line 678 ⟶ 696:
setlength(Numbers,0);
end;
T0 := GetTickCount64GetCPU_Time-T0;
Writeln('Max Uint64 ',Numb2USA(IntToStr(High(Uint64))));
writeln('Total runtime : ',T0/CPU_hz:0:6,' GigaCyles');
{$IFDEF WINDOWS}
readln;
Line 684 ⟶ 704:
setlength(CombIdx,0);
end.</lang>
{{out|Output @ Tio.run}}
{{Out}}
<pre style="height:260px">
TIO.RUN User time: 12.905 s //Total runtime : 29.470650 GigaCyles estimated ~2,28 Ghz
Up to 19 Digits:
Exponent : 2 used 275 recursions in 0.000030 GigaCyles
TIO.RUN Real time: 10.699 s CPU share: 98.66 %
Exponent : 2 used 275 recursions
 
Exponent : 3 used 990 recursions in 0.000161 GigaCyles
153 + 370 + 371 + 407 = sum to 1,301
 
Exponent : 4 used 2992 recursions in 0.000367 GigaCyles
1,634 + 8,208 + 9,474 = sum to 19,316
 
Exponent : 5 used 7997 recursions in 0.001193 GigaCyles // /2.28 -> 523 µs
4,150 + 4,151 + 54,748 + 92,727 + 93,084 + 194,979 = sum to 443,839
 
Exponent : 6 used 19437 recursions in 0.003013 GigaCyles
548,834 = sum to 548,834
 
Exponent : 7 used 43747 recursions in 0.007827 GigaCyles
1,741,725 + 4,210,818 + 9,800,817 + 9,926,315 + 14,459,929 = sum to 40,139,604
 
Exponent : 8 used 92367 recursions in 0.017619 GigaCyles
24,678,050 + 24,678,051 + 88,593,477 = sum to 137,949,578
 
Exponent : 9 used 184745 recursions in 0.037308 GigaCyles
146,511,208 + 472,335,975 + 534,494,836 + 912,985,153 = sum to 2,066,327,172
 
Exponent : 10 used 352705 recursions in 0.090797 GigaCyles
4,679,307,774 = sum to 4,679,307,774
 
Exponent : 11 used 646635 recursions in 0.207819 GigaCyles
32,164,049,650 + 32,164,049,651 + 40,028,394,225 + 42,678,290,603 + 44,708,635,679 + 49,388,550,606 + 82,693,916,578 + 94,204,591,914 = sum to 418,030,478,906
 
Exponent : 12 used 1144055 recursions in 0.295691 GigaCyles
 
Exponent : 13 used 1961245 recursions in 0.532789 GigaCyles
564,240,140,138 = sum to 564,240,140,138
 
Exponent : 14 used 3268749 recursions in 0.937579 GigaCyles
28,116,440,335,967 = sum to 28,116,440,335,967
 
Exponent : 15 used 5311724 recursions in 1.623457 GigaCyles
 
Exponent : 16 used 8436274 recursions in 2.680338 GigaCyles
4,338,281,769,391,370 + 4,338,281,769,391,371 = sum to 8,676,563,538,782,741
 
Exponent : 17 used 13123099 recursions in 4.432118 GigaCyles
233,411,150,132,317 + 21,897,142,587,612,075 + 35,641,594,208,964,132 + 35,875,699,062,250,035 = sum to 93,647,847,008,958,559
 
Exponent : 18 used 20029999 recursions in 7.169892 GigaCyles
 
Exponent : 19 used 30045004 recursions in 11.431518 GigaCyles
1,517,841,543,307,505,039 + 3,289,582,984,443,187,032 + 4,498,128,791,164,624,869 + 4,929,273,885,928,088,826 = sum to 14,234,827,204,843,405,766
 
Max Uint64 18,446,744,073,709,551,615
Total runtime : 29.470650 GigaCyles</pre>
</pre>
 
=={{header|Perl}}==
Anonymous user