Before you cringe at the duplicate title, the other question wasn\'t suited to what I ask here (IMO). So.
I am really wanting to use virtual functions in my applicat
I think that this kind of testing is pretty useless, in fact:
1) you are wasting time for profiling itself invoking gettimeofday()
;
2) you are not really testing virtual functions, and IMHO this is the worst thing.
Why? Because you use virtual functions to avoid writing things such as:
switch typeof(object) {
case ClassA: functionA(object);
case ClassB: functionB(object);
case ClassC: functionC(object);
}
in this code, you miss the "if... else" block so you don't really get the advantage of virtual functions. This is a scenario where they are always "loser" against non-virtual.
To do a proper profiling, I think you should add something like the code I've posted.