[SDL] Re: BeOS and SDL
f91-men at nada.kth.se
Thu Aug 3 14:10:04 PDT 2000
>> My only question, how fast is inheritance compared to a switch?
>Inheritance is faster than a switch, usually. Inheritance works like
>function pointers, there is a small overhead, but the decision-making is
>all done at once (when the object is created).
Most modern CPUs do a fair job on predicting branches, but most do not
at all as well in the indirect function call prediction business.
(Most tests I've done confirm this.)
When you compare a switch to a virtual function call (which is basically
a indirect function call + the cost of fetching the pointer from the vtbl),
it depends on what code is emitted for the switch, how many branches etc.
Compilers often emit branch trees and/or jump tables for switches,
depending on the number and distribution of the case labels.
So the right answer is the one you don't want: "It depends" :-)
More information about the SDL