Re: MODULEand USE versus Argument Passing
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 09:14:21 -0700
Herman D. Knoble wrote:
Given a Subprogram that gets called millions of times, we know that there is (CPU) overhead for subprogram linkage.
My question is, independent of compilers, which is more efficient in practice:
passing a list of (say 3 to 10) arguments to a subprogram's corresponding parameters, OR using a Module and companion USE statement,
OR use named COMMON?
It depends much on the processor architecture, (and linkage convention), and not so much on the compiler.
On most systems arguments are passed by reference (address) requiring an indirect reference. Assumed size arrays are also passed similarly, requiring an offset (into the array) from the passed address.
COMMON might be statically addressed, and so not require the indirect addressing, or it might be about the same. Though COMMON only works if you pass the same parameters every time you call the routine.
For assumed shape arrays, a descriptor must be passed including the dimensions and even more indirect access to the data.
I don't know so well the implementation of module and USE, I will guess it is similar to COMMON with one more level of indirection.
All the above should be fast enough for most normal uses.
There are conditions where the compiler must pass a copy of an
array, and copy it back on return. If you don't access much of
the array, the overhead can be large. If you access it a few times,
you might not notice so much. If you access each array element a large number of times, the copy might be faster as it is in contiguous storage and the cache works better that way.
In all cases, it makes a big difference to access an array in the order elements are in storage, normally with the leftmost subscript varying fastest.
Otherwise, you will need to supply more details to get a better answer.
-- glen
.
- References:
- MODULEand USE versus Argument Passing
- From: Herman D . Knoble
- MODULEand USE versus Argument Passing
- Prev by Date: Re: MODULEand USE versus Argument Passing
- Next by Date: Re: I have no ideas what can it be!
- Previous by thread: Re: MODULEand USE versus Argument Passing
- Next by thread: Re: MODULEand USE versus Argument Passing
- Index(es):
Relevant Pages
|