Re: template classes faster than derived classes?

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

 



Hi Nav,
On Tue, Nov 24, 2009 at 08:53:11PM +0000, Nava Whiteford wrote:
> >> http://linuxjunk.blogspot.com/2009/11/are-templates-faster-than-subclasses.html
> 
> > I didn't see the first version.  In the current version, the templated  
> > code is simple enough that the optimizer can figure out the whole thing  
> > and skip everything.  The virtual code is not simple enough, so the code  
> > actually executes.
> 
> Ah ok, so it's able to optimise my loop in to a single multiply here?  That's neat.
> 
> > So you still aren't measuring what you set out to measure.
> 
> I've constructed a slightly more complicated test:
> 
> http://linuxjunk.blogspot.com/2009/11/templates-v-subclasses-v2.html
> 
> In this case the templated version doesn't seem to have the same huge
> advantage. Templated 20.73s against 21.1s for the classed version. I would guess
> real, but not huge.

May be another test would be to use a very simple function - and in
addition forbid gcc to inline or optimize away the function calls:
If you define the function as:
int get_i() __attribute__((noinline)){
  asm("");
  return i*i;
}
it will be neither inlined nor the calls can't be optimized away (see
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html).
Then, you really can make the functions as small as possible (e.g. doing
nothing) and compare the time needed to call them.

Axel

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux