Результатом работы будет файл с подробным описанием тестов и временем их исполнения в Сотых Долях Секунды.
Код
program Big_experiment;
{$N+}
uses crt, dos;
var resSingle : single;
resDouble : double;
resReal : real;
resExtended : extended;
n : longint;
h , h1 , m , m1, s, s1 , hd , hd1 :extended;
hw , h1w , mw , m1w, sw, s1w , hdw , hd1w :word;
{---}
function CalcTime:extended;
var res : extended;
begin
res := 0;
res := abs( (hd-hd1) + ((s*100)-(s1*100)) + ((m*6000)-(m1*6000)) + ((h*360000)-(h1*360000)));
calctime := res;
end;
{---}
procedure exp(flag :byte;direction :boolean); {direction : true - left to right; false right to left}
var i : longint;
t : extended;
begin
i := 1;
repeat
t:=(i*2)-1;
if not(direction) then t := (n+1-t)*2-1;
case flag of
1 : resSingle := resSingle + 1 /(t*t);
2 : resDouble := resDouble + 1 / (t*t);
3 : resReal := resReal + 1 / (t*t);
4 : resExtended := resExtended + 1 / (t*t);
end;
inc(i);
until (i=n);
end;
{---}
{---}
var f : text;
i : longint;
nam : array[1..4] of string;
begin
resSingle := 0;
resDouble := 0;
resReal := 0;
resExtended :=0;
nam[1] := 'Single';
nam[2] := 'Double';
nam[3] := 'Real';
nam[4] := 'Extended';
assign(f,'big_res.txt');
rewrite(f);
clrscr;
n := 1000;
repeat
for i := 1 to 4 do begin
writeln(f,nam[i] , ' n=',n);
gettime(hw,mw,sw,hdw);
h := hw; m := mw; s := sw; hd := hdw;
exp(i,true);
gettime(h1w,m1w,s1w,hd1w);
h1 := h1w; m1 := m1w; s1 := s1w; hd1 := hd1w;
case i of
1 : writeln(f,'Left to right :',resSingle, ' with ',CalcTime:2:0,' ss');
2 : writeln(f,'Left to right :',resDouble, ' with ',CalcTime:2:0,' ss');
3 : writeln(f,'Left to right :',resReal, ' with ',CalcTime:2:0,' ss');
4 : writeln(f,'Left to right :',resExtended, ' with ',CalcTime:2:0,' ss');
end;
writeln(nam[i] , ' ',CalcTime :2:0,' ss ');
resSingle := 0;
resDouble := 0;
resReal := 0;
resExtended :=0;
gettime(hw,mw,sw,hdw);
h := hw; m := mw; s := sw; hd := hdw;
exp(i,false);
gettime(h1w,m1w,s1w,hd1w);
h1 := h1w; m1 := m1w; s1 := s1w; hd1 := hd1w;
case i of
1 : writeln(f,'Right to left',resSingle,' with ',CalcTime:2:0,' ss');
2 : writeln(f,'Right to left',resDouble,' with ',CalcTime:2:0,' ss');
3 : writeln(f,'Right to left',resReal,' with ',CalcTime:2:0,' ss');
4 : writeln(f,'Right to left',resExtended,' with ',CalcTime:2:0,' ss');
end;
writeln(f,'Pi^2 / 8 :' , (pi*pi)/8);
writeln(f);
writeln(nam[i] , ' ',CalcTime :2:0,' ss ');
end;
writeln(n);
n := n * 10;
until (n= 1000000000);
writeln;
writeln('Detailed results was saved in BIG_RES.txt . Thank you for using my test. (ss = sec/100)');
readkey;
close(f);
end.
Призываю всех отказаться от использования типа REAL , в связи с тем , что он примерно в 2 раза медленее остальных !