C++ 14 Apr 2010 20:41:21
C++ dynamic_cast Performance
(Updated 2010-10-27: Re-run the test with latest clang++ from subversion)
A performance comparison of the speed of dynamic_cast operations in C++.
Idea from http://www.nerdblog.com/2006/12/how-slow-is-dynamiccast.html, who did not provide any source so I wrote my own more extensive tests.
Sources
- Ticks counted via cycle.h (local mirror)
- Source: speed-dynamic-cast.cpp
Things Tested
- reinterpret_cast on a known type
- virtual function call + reinterpret_cast
- member variable access + reinterpret_cast
- successful dynamic_cast to its own type
- successful dynamic_cast from the derived levels to lower levels
- failed dynamic_cast from the derived levels to an unrelated type
