comp.lang.ada
 help / color / mirror / Atom feed
* GNAT function calling overhead
@ 1995-04-06  0:00 Duncan Sands
  1995-04-06  0:00 ` Colin James III
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Duncan Sands @ 1995-04-06  0:00 UTC (permalink / raw)


system: DOS 486 (with math coprocessor), gcc 2.6.3, GNAT 2.03

Essentially the question is: why so much function calling overhead
in GNAT?

I'm writing a set of matrix factorization routines (Schur etc) so
of course I need routines for multiplying matrices etc.
For me a matrix is
   type Matrix is array(Positive range <>, Positive range <>) of Float;

I overloaded "*" for matrix multiplication:
   function  "*"(Left : in Matrix; Right : in Matrix) return Matrix;

Multiplying two 15 by 15 matrices 10_000 times using this function
takes about 55 seconds on my machine.  The algorithm is the obvious
one: loop over rows and columns, add up the appropriate products and
assign them.

I then "inlined" this function: rather than using "*", I put the code
for "*" directly into my 10_000 times loop, of course renaming Left
and Right to the names of my matrices, and assigning directly to the
matrix which is to hold the answer.  In this way I eliminated the
function calling overhead.  Using this method, multiplying two 15 by
15 matrices 10_000 times takes about 44 seconds.

All this was done with optimisation (-O3) and -gnatp (i.e. no range
checking etc).

In summary: 55 seconds with function calling overhead.
            44 seconds without function calling overhead.

Now, a 15 by 15 matrix means 225 entries.  225 entries at,
say, 8 bytes an entry makes a bit less than 2k.  So, depending on
whether GNAT takes function parameters by reference or by copy,
this makes anything between 2k and, say, 10k bytes to be copied
on each function call.

Does this explain the time difference?  It shouldn't!  The amount
of time spent copying memory should be completely overwhelmed by
the amount of time taken to do the floating point operations!
That is, for each of the 225 entries there are 15 floating point
multiplications to be performed.  The amount of time taken to
copy the 225 entries, even if you need to copy them several times,
should be MUCH smaller than the amount of time spent in the
calculation.  But the timings above indicate that function
calling overhead makes up something like 25% of the time taken!

So, the question is: why so much function calling overhead in GNAT?

Can anyone please enlighten me?

Thanks a lot,

Duncan Sands.

PS: The corresponding C code takes about 6 seconds.  This surprises
me too.




^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~1995-04-07  0:00 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-04-06  0:00 GNAT function calling overhead Duncan Sands
1995-04-06  0:00 ` Colin James III
1995-04-06  0:00   ` Robb Nebbe
1995-04-07  0:00     ` Robert Dewar
1995-04-07  0:00     ` Duncan Sands
1995-04-06  0:00   ` Samuel Tardieu
1995-04-07  0:00   ` Tom Griest
1995-04-07  0:00     ` Robert Dewar
1995-04-07  0:00   ` Philip Brashear
1995-04-07  0:00   ` Robert Dewar
1995-04-06  0:00 ` Norman H. Cohen
1995-04-07  0:00 ` Robert Dewar
1995-04-07  0:00 ` Theodore Dennison
1995-04-07  0:00   ` Robert Dewar
1995-04-07  0:00 ` Kenneth Almquist
1995-04-07  0:00   ` Robert Dewar
1995-04-07  0:00   ` Colin James III
1995-04-07  0:00     ` Robert Dewar
1995-04-07  0:00   ` Larry Kilgallen
1995-04-07  0:00     ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox