Darkrai1337

Untitled

Jan 11th, 2022
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.35 KB | None | 0 0
  1. program Lab4;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Math;
  8.  
  9. function GetTSC(): Int64; register;
  10. asm
  11. RDTSC
  12. end;
  13.  
  14. var
  15.   StartTSC, EndTSC, Freq: Int64;
  16.   x, R, L, d,temp,clock: double;
  17.   i: integer;
  18.  
  19. function Factorial(N: integer): extended;
  20. var j: integer;
  21. begin
  22.   Result:= 1;
  23.   for j:= 1 to N do
  24.     Result:= Result * j;
  25. end;
  26.  
  27. begin
  28.   StartTSC:= GetTSC();
  29.   Sleep(1000);
  30.   EndTSC:= GetTSC();
  31.   Freq:= EndTSC - StartTSC;
  32.   temp:=Freq/1e9;
  33.   Writeln('frequency: ',temp:4:7, ' gHz');
  34.  
  35.   write('x=');
  36.   readln(x);
  37.   L:= (Exp(x) - 1/Exp(x)) * 0.5;
  38.   Writeln('L = ', L:18:18);
  39.   R:= 0;
  40.   i:= 0;
  41.   StartTSC := GetTSC();
  42.   repeat
  43.     Inc(i);
  44.     d := intpower(x, 2*i-1) / Factorial(2*i-1);
  45.     R:= R + d;
  46.   until d < 1e-6;
  47.  
  48.   EndTSC :=  GetTSC();
  49.   clock := EndTSC-StartTSC;
  50.   Writeln('iterative R = ', R:18:18, '   i = ', i);
  51.   writeln('Clock = ',clock :5:5);
  52.   temp:=(EndTSC - StartTSC)/Freq*1e6;
  53.   writeln('time = ', temp:5:5, ' mcs');
  54.  
  55.   R:=x;
  56.   i:= 1;
  57.   d:= x;
  58.   StartTSC := GetTSC();
  59.   repeat
  60.     Inc(i);
  61.     d := d * sqr(x) / ((2*i-2)*(2*i-1));
  62.     R:= R + d;
  63.   until d < 1e-6;
  64.  
  65.   EndTSC :=  GetTSC();
  66.   clock := EndTSC-StartTSC;
  67.   Writeln('recursive R = ', R:18:18, '   i = ', i);
  68.   writeln('Clock = ',clock :5:5);
  69.   temp:=(EndTSC - StartTSC)/Freq*1e6;
  70.   writeln('time = ', temp:5:5, ' mcs');
  71.   readln;
  72. end.
  73.  
Advertisement
Add Comment
Please, Sign In to add comment