[comp.lang.fortran] summary: speed of COMMON vs arguments

staff@cadlab.sublink.ORG (Alex Martelli) (04/09/90)

> Recently, I asked the net:
>>...  Is it faster to pass variables to a subroutine via
>>arguments or via a COMMON block?  Same question re. passing back results
>>to the calling routine....  It will run on VAX FORTAN ....

Sorry to have missed it the first time  around!  This is highly dependent
on the calling-conventions of the compiler.  On many modern architectures,
full of registers and with zippy compilers (and maybe with sliding
register windows to boot), the compiler will be able to place up to
N arguments to a subroutine IN REGISTERS, while stuff which is placed
into COMMON blocks, barring hypothetical and science-fictional
global super-duper-optimizers, WILL have to go into memory and back
(those global optimizers that ARE around require you to pass ALL
source code each time... not really practical for programs of any
size, using libraries bought elsewhere, etc).
On such compilers and architectures, there is NO doubt that arguments
passed as arguments WILL be faster (MUCH faster) than COMMON blocks.
On more ancient machines/compilers, it's likely to be the other way
'round, as other respondents suggested.

> I may have asked a BOZO question, but I think it's smart to never
> be afraid to do so.  And I did get several requests for a summary.

Not AT ALL!  Many people believe they "know" which way to code for
optimization, based on factoids picked up here and there or maybe 
on one introductory course on compiler theory taken years ago...
and they generally mess things up for some compilers or architectures
(you should see what happens on a VECTOR machine if you are too
clever by half in your coding...!).  THANKS for asking!
-- 
Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 45, Bologna, Italia
Email: (work:) staff@cadlab.sublink.org, (home:) alex@am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only; any time of day or night).