[comp.lang.pascal] proc calls

mglacy@lamar.ColoState.EDU (02/06/91)

I have a fair sized numerical analysis program I'm working on.  In the
middle of it is the workhorse procedure that eats up about 90% of
run time.  'workhorse' looks something like this:

PROCEDURE workhorse;
   procedure A
   begin
       if some condition
	  call A {recursively}
       else 
	  do a bunch of calculations I'll call C
   end;{A}
   begin
	{main part of workhorse}
	initlz;
	Do procedure A
	process results of A
   end; {workhorse}


Here's the thing:  In the interests of style, I decided to make the
bunch of calculations C into a procedure.  This necessitates passing
a number of parameters, including a big array {ca 50k elements}.
To avoid excess memory use, particularly given the recursive calls of 
A, I made the big array a VAR parameter.  (In the original version 
above, I just left the big array as global to procedure workhorse).

The program works either way but:
   1. both versions run equally fast under turbo pascal 4.0
   2. but using a vax running VMS and IBM AIX  system, the second
      version, with the procedure for the set of calculations C,
      runs  about 30% slower.

Question: Can anybody explain this to me---I have a hard time imagining
that some parameter passing and proc calls would eat up about 30% as 
much time as the whole workhorse procedure.   I've tried the optimizing
compiler option on the IBM AIX system, with function/procedures results put
into special registers, etc.  Still, the TP  compiler seems to be
the only one that will me to improve the style of the program without
a major sacrifice in execution time.

Enlightment would be appreciated.