template classes faster than derived classes?

Nava Whiteford new@sgenomics.org
Tue Nov 24 20:53:00 GMT 2009


>> 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.

Do these numbers seem reasonable?

Nav



More information about the Gcc-help mailing list