r/cpp • • May 26 '22

Dynamic polymorphism performance

https://thecppdev.com/2022/05/26/dynamic-polymorphism-performance/?amp=1
2 Upvotes

15 comments sorted by

View all comments

7

u/Pragmatician May 26 '22

In the "static polymorphism" example, there is no polymorphism at all. You're just using one concrete type. CRTP is not static polymorphism.

It’s worth to mention that a call to a virtual function is 25% slower than a call to a normal function.

[citation needed]

5

u/no-sig-available May 26 '22

If a virtual call takes 1.25 nanoseconds instead of 1.0, I can live with that.

Not that I have ever written a virtual function that doesn't do anything.

0

u/pandorafalters May 26 '22

Depending on the function, I could even happily accept an overhead of multiple milliseconds in exchange for reduced cognitive effort. I don't think I've ever encountered a case nearly that pessimistic, though.