c++casting

dynamic_cast overhead in C++


I know that dynamic_cast performs a runtime check and therefore is considered safer (can return null pointer on failure) but slower then static_cast. But how large is the difference in overhead between the two?

Should I really consider using static_cast in loops for performance reasons in regular large projects? Or is the difference minor and only relevant for special real-time programs?


Solution

  • Did you profile it?

    The rule is:

    It's as simple as that. All other considerations are secondary.