Hi, the code is short, so I think I can attach it here. It uses both dynamic and static arrays, but to my surprise the difference in time is slight.
-------------------------------------------------------- program arspeed;
uses GPC;
type
PMatr2Dob = ^TMatr2Dob; TMatr2Dob (Size1, Size2: Integer) = array [ 1 .. Size1, 1..Size2 ] of double;
PVecDob = ^TVecDob; TVecDob (Size: Integer) = array [ 1 .. Size ] of double;
const mn = 5000;
var
matrdyn: PMatr2Dob; vecdyn: PVecDob;
matrstat: array [ 1..mn, 1..mn ] of double; vecstat: array [ 1..mn ] of double;
i, j, k, ntimes, itime: integer; r1, r2, deltat, deltaperc: double;
time1, time2 : longCard;
begin
new (matrdyn, mn, mn); new (vecdyn, mn); ntimes := 5;
writeln ('# filling up DYNAMIC array [', mn, ', ', mn, '] with random doubles ', ntimes, ' times.' );
time1 := GetMicroSecondTime;
for itime := 1 to ntimes do begin
for i := 1 to mn do begin for j := 1 to mn do begin r1 := random; matrdyn ^[ i, j ] := r1; end; end;
end; //end itime
time2 := GetMicroSecondTime; writeln('DYNAMIC array: total elapsed time = ', ( (time2-time1) * 0.000001):7:2, ' seconds.' );
for i := 1 to 3 do writeln;
writeln ('# filling up STATIC array [', mn, ', ', mn, '] with random doubles ', ntimes, ' times.' ); time1 := GetMicroSecondTime;
for itime := 1 to ntimes do begin
for i := 1 to mn do begin for j := 1 to mn do begin r1 := random; matrstat [ i, j ] := r1; end; end;
end; //end itime
time2 := GetMicroSecondTime; writeln('STATIC array: total elapsed time = ', ( (time2-time1) * 0.000001):7:2, ' seconds.' );
for i := 1 to 3 do writeln;
ntimes := 1000; writeln ('# filling up DYNAMIC array [', mn, '] with random doubles ', ntimes, ' times.' ); time1 := GetMicroSecondTime;
for itime := 1 to ntimes do begin
for i := 1 to mn do begin vecdyn ^[ i ] := random; end;
end; //end itime
time2 := GetMicroSecondTime; writeln('DYNAMIC array: total elapsed time = ', ( (time2-time1) * 0.000001):7:2, ' seconds.' );
for i := 1 to 3 do writeln;
writeln ('# filling up STATIC array [', mn, '] with random doubles ', ntimes, ' times.' ); time1 := GetMicroSecondTime;
for itime := 1 to ntimes do begin for i := 1 to mn do begin vecstat [ i ] := random; end; end; //end itime
time2 := GetMicroSecondTime; writeln('STATIC array: total elapsed time = ', ( (time2-time1) * 0.000001):7:2, ' seconds.' );
end.
--------------------------------------------------------
As for comparing with G77, I agree, this would be fairer, but I am trying to make my code as fast as possible, and I should choose whether to begin translating it into Fortran. While I like Pascal a lot better, unfortunately I cannot afford to lose all this amount of performance. Thanks for your help
Silvio
| There are many reasons why GPC may be slower and many ways to speed up | programs. Post the code (or a link if it is large) -- otherwise all | what we can say would be pure speculation. Also, it may be usefull to | compare GNU Fortran and Intel Fortran -- since GNU Pascal and GNU Fortran | use the same backend, such comparison would separate effect of | different language from differences in backends.