January 2019
Intermediate to advanced
512 pages
14h 5m
English
Before we can talk about a better alternative to a virtual function, we should consider why we would want to have an alternative at all. What is not to like about virtual functions?
The problem is the performance overhead. A virtual function call can be several times more expensive than a non-virtual call, more for very simple functions that would have been inlined were they not virtual (recall that a virtual function can never be inlined). We can measure this difference with a microbenchmark, the ideal tool for measuring the performance of small fragments of code. There are many microbenchmark libraries and tools out there; in this book, we will use Google Benchmark library. To follow along with the ...