Monthly ArchiveApril 2010
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
C++ 02 Apr 2010 19:11:11
C++ Set Performance
(newer version from 2012-02-20, older std::map benchmarks for GNU g++ 4.3.2 and MSVC++ 2010 beta 2)
A performance comparison of the speed of operations on the various set implementations used in C++. There are 16383 unique elements across which 1000000 insert, lookup, iterate, and erase operations are performed.
And this time I’ve left the raw tick numbers and enabled table sorting so you can compare for yourself. Just be aware that the Linux and Windows numbers cannot be compared against each other.
Sources
- Containers: std::set, std::unordered_set, boost::unordered_set, sorted_vector, sorted_deque
- Ticks counted via cycle.h (local mirror)
- Source: speed-set-int.cpp and speed-set-string.cpp