Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab4;
- {$APPTYPE CONSOLE}
- uses
- SysUtils,
- Math;
- function GetTSC(): Int64; register;
- asm
- RDTSC
- end;
- var
- StartTSC, EndTSC, Freq: Int64;
- x, R, L, d,temp,clock: double;
- i: integer;
- function Factorial(N: integer): extended;
- var j: integer;
- begin
- Result:= 1;
- for j:= 1 to N do
- Result:= Result * j;
- end;
- begin
- StartTSC:= GetTSC();
- Sleep(1000);
- EndTSC:= GetTSC();
- Freq:= EndTSC - StartTSC;
- temp:=Freq/1e9;
- Writeln('frequency: ',temp:4:7, ' gHz');
- write('x=');
- readln(x);
- L:= (Exp(x) - 1/Exp(x)) * 0.5;
- Writeln('L = ', L:18:18);
- R:= 0;
- i:= 0;
- StartTSC := GetTSC();
- repeat
- Inc(i);
- d := intpower(x, 2*i-1) / Factorial(2*i-1);
- R:= R + d;
- until d < 1e-6;
- EndTSC := GetTSC();
- clock := EndTSC-StartTSC;
- Writeln('iterative R = ', R:18:18, ' i = ', i);
- writeln('Clock = ',clock :5:5);
- temp:=(EndTSC - StartTSC)/Freq*1e6;
- writeln('time = ', temp:5:5, ' mcs');
- R:=x;
- i:= 1;
- d:= x;
- StartTSC := GetTSC();
- repeat
- Inc(i);
- d := d * sqr(x) / ((2*i-2)*(2*i-1));
- R:= R + d;
- until d < 1e-6;
- EndTSC := GetTSC();
- clock := EndTSC-StartTSC;
- Writeln('recursive R = ', R:18:18, ' i = ', i);
- writeln('Clock = ',clock :5:5);
- temp:=(EndTSC - StartTSC)/Freq*1e6;
- writeln('time = ', temp:5:5, ' mcs');
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment