Your program is certain to be IO bound. This is not a good test of the cost of any of your computations (unless that cost is IO). If you have a program which can use inlined template functions instead of virtual function calls, and the function is "called" very frequently, the inlined template functions should be much faster (this is more due to saving of registers, etc, rather than the virtual function lookup). This is a rule of thumb, not a guarantee. My hunch is that you need to construct a better benchmark (hint, make sure your call overhead is the bottleneck, and not IO (cout), and make sure that all of your results are actually used, otherwise they may be optimized out). Brian On Tue, Nov 24, 2009 at 11:44 AM, Nava Whiteford <new@xxxxxxxxxxxxx> wrote: > Hi, > > Are template classes faster than using a virtual derived class via a > pointer to its base class? > > Intuition tells me it should be faster, and reasonably significantly so. > However I put together the following test: > > http://linuxjunk.blogspot.com/2009/11/are-templates-faster-than-subclasses.html > > Which suggests to me that there isn't really a lot in it. > > I'd welcome any comments on this. > > Nav >