Dear Frank and Adriaan,
From Frank: If your version doesn't recognize `{$R-}', it's probably older and doesn't do range-checking at all, so you don't need to worry.
Thank you, and I have determined that the indexing performed for the dynamic schemata are as fast as my own pointer arithmetic. With the schemata instead of pointer arithmetic, my code is now half as long, and far more readable. Converting my code to GPC has been a real pleasure, and I continue to discover new and delightful features.
From Adriaan: I can hardly believe it's the generated code, but nothing is impossible ... If you send me the source code, I will have a look at it (but I have very limited time available this month).
Your offer is most generous. I have done some work to try and make your investigation simpler.
I am comparing the CW Pascal compiler issued about five years ago with the GPC compiler I installed two months ago. The CW code runs in MacOS 9. The GPC code runs in MacOS X from the UNIX terminal.
Here is my GPC test program:
program test;
var a:real; m,n,p:integer;
begin a:=1234.567; writeln('starting loop...'); for m:=0 to 1000 do for n:=0 to 1000 do begin for p:=1 to 100 do begin { loop statement here } end; end; writeln('done.'); end.
In CW the code looks the same, but the variables are longreals and longints so that they match the GPC sizes. As you can see, the loop statement gets executed 100,000,000 times. I measure the execution time by counting seconds in my head between the prints to the console. I'm using an 800 MHz iBook. Here are my results:
loop CW time GPC time statement (s) (s)
none 1 3 a:=a*a/a 6 13 a:=p 3 6 a:=round(a) 8 40 a:=sin(p) 15 40
Most things take two or three times as long with GPC. I expect code running on MacOS X (UNIX) to be slower than code on MacOS 9 because MacOS X is re-entrant, is subject to pre-emptive multitasking, and provides protected memory. I am more interested in the fact that the GPC round() function takes four times as long as the GPC implementation of a:=a*a/a, while the CW round() function takes about the same time as the CW implementation of a:=a*a/a.
As you know, rounding a number with platform-independent mathematical functions is slow. The CW round() probably uses the Power PC real number format to abbreviate the rounding process. Perhaps GPC uses a platform- independent implementation.
I have always used round() with sinusoidal look-up tables in my fourier transforms. The above results suggest that I gained very little by doing so. Nevertheless, I also use round() to obtain display coordinates from real-valued graphs, and these routines are running five times slower than before.
Yours, Kevan Hashemi