On 05/31/10 14:30, Basile Starynkevitch wrote:
[snip]
> I would believe that replacing a complex function like above (which
> contains a switch) with a virtual function call could probably be a win
> in performance, not a loose.
>
> But perhaps my intuition is wrong. Honestly, I don't have exact figures
> of the cost of virtual calls. IIRC, they have been costly for Intel
> processors more than 5 years ago (but AMD processors perhaps run them
> quicker at that time), but current Intel & AMD processors probably deal
> better with indirect jump, so a virtual call is perhaps a with w.r.t. a
> complex switch like above.
[snip]
The following post to the boost devel list:

http://sourceforge.net/mailarchive/message.php?msg_name=3f49a9f41003031715g19a23b94p47ccec2251acd55%40mail.gmail.com

claims that switch statements are faster than virtual function calls.

There's also this boost devel list post:

http://lists.boost.org/Archives/boost/2008/01/132074.php

where, instead of a virtual function table, a vector of function
pointers is used.  Using this method, I assume, would have a speed
comparable to that of using a virtual function table since a virtual
function table, IIUC, is essentially a vector of function pointers.
However, that boost devel post claims using a switch statement would
be faster.

HTH.

-regards,
Larry

Reply via email to