help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gprof and inline methods


From: address@hidden
Subject: gprof and inline methods
Date: 27 Oct 2004 13:07:24 -0700

Hello everybody

I just examined my project with gprof because it runs much slower than
it should and I got a highly strange result. Well, here are the first
lines of the gprof output:

>  %   cumulative   self              self     total           
> time   seconds   seconds    calls   s/call   s/call  name    
> 24.13     19.80    19.80    12000     0.00     0.00  
> HeightmapDrawer::drawGridLine(HeightmapData::Position const&, int, bool)
> 17.00     33.75    13.95 105069348     0.00     0.00  
> HeightmapData::Position::getX() const
> 10.56     42.41     8.66 24000270     0.00     0.00  
> HeightmapDrawer::isPointVisible(HeightmapData::Position const&)
>  8.42     49.33     6.91 24000000     0.00     0.00  
> HeightmapData::Position::operator+=(HeightmapData::Position const&)
>  8.26     56.10     6.78        3     2.26     7.62  
> HeightmapDrawer::drawRect(HeightmapData::Position const&, int, int, 
> HeightmapDrawer::Reduction)
>  7.54     62.30     6.19 66192969     0.00     0.00  
> HeightmapData::Position::getZ() const
>  5.59     66.89     4.59 11973162     0.00     0.00  
> HeightmapDrawer::isRectVisible(HeightmapData::Position, int, int)
>  4.22     70.34     3.46 12009298     0.00     0.00  
> HeightmapData::Position::Position(int, int)
>  4.22     73.81     3.46     6719     0.00     0.00  
> HeightmapData::PointData::PointData(HeightmapData::PointData const&)
>  4.17     77.23     3.42 24011949     0.00     0.00  
> HeightmapDrawer::endDrawing()
> [...]

As you can see, the second most time expensive method is
HeightmapData::Position::getX() const. The funny fact is: it is a
inline method that just consists of a return statement. It is defined
like this:

int getX() const {return x;}

How can this method take such a long time (ok, i see it is the most
frequently called methed of all, but its just a return statemend).
There's another method of that object in the top 10:
HeightmapData::Position::operator+=(HeightmapData::Position const&).
This one just adds 2 integer parameter and is defined like this:

Position& operator += (const Position& p)
        {x+=p.x; z+=p.z; return *this;}

Some informations to my code: As you can guess, it really uses the
class HeightmapData::Position a lot in loops. But this class simply
stores a 2 dimensional position. Would you suggest me to use an array
or c-style struct instead (I would hate to)?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]