At the CPU level, there is only one kind of function , and it very much resembles the C-type. You can create your own, but ...
As it turned out, C ++, built with efficiency in mind, displays most functions directly for invocation commands:
- The namespace level function is similar to the regular C function
- the static method is similar to a namespace level function (in terms of invocation)
- the non-static method is very similar to the static method, except that the implicit
this parameter is passed on top of other parameters (one pointer)
All three of these have the same level of performance.
virtual methods, on the other hand, have little overhead. A C ++ technical performance report was presented that estimated overhead compared to the non-virtual method between 10% and 15% (from memory) for empty functions. This means that for any function with meat inside (i.e., performing real work), the overhead by itself is close to delusion in noise. The real cost comes from braking the insert if the virtual call cannot be output at compile time.
Matthieu M.
source share