C++ 04 Oct 2009 15:21:48
C++ Map Speeds, MSVC++ Edition
(There is also a GNU g++ Edition of these performance tests, and a newer std::set comparison.)
Here is a complete test of MSVC++ map speeds, using same code as my previous map speed test: timemap.cpp with cycle.h.
The compilers are Microsoft Visual C++ 2008 Express as VC9 and Microsoft Visual C++ 2010 Beta as VC10. The containers are std::map, stdext::hash_map, std::tr1::unordered_map, and boost::unordered_map, each with _SECURE_SCL enabled and disabled.
The results, where std::map with _SECURE_SCL enabled is set to 100%, and lower is better:
<int,int> | Insert | Lookup | Iterate | Erase |
---|---|---|---|---|
VC9 std::map SCL=1 | 100.00% | 100.00% | 100.00% | 100.00% |
VC9 stdext::hash_map SCL=1 | 112.00% | 127.38% | 528.65% | 130.07% |
VC9 std::tr1::unordered_map SCL=1 | 111.63% | 128.45% | 534.87% | 157.24% |
VC9 boost::unordered_map SCL=1 | 55.11% | 9.13% | 38.77% | 28.82% |
- | ||||
VC9 std::map SCL=0 | 100.11% | 107.19% | 93.81% | 98.85% |
VC9 stdext::hash_map SCL=0 | 88.96% | 70.56% | 546.17% | 101.48% |
VC9 std::tr1::unordered_map SCL=0 | 89.33% | 61.26% | 543.59% | 98.22% |
VC9 boost::unordered_map SCL=0 | 52.30% | 8.38% | 32.44% | 27.84% |
- | ||||
VC10 std::map SCL=1 | 106.64% | 114.93% | 94.85% | 107.75% |
VC10 std::tr1::unordered_map SCL=1 | 213.29% | 216.05% | 51.13% | 169.92% |
VC10 boost::unordered_map SCL=1 | 54.80% | 11.02% | 38.12% | 25.14% |
- | ||||
VC10 std::map SCL=0 | 98.01% | 95.26% | 90.87% | 88.27% |
VC10 std::tr1::unordered_map SCL=0 | 121.01% | 70.59% | 28.32% | 81.65% |
VC10 boost::unordered_map SCL=0 | 52.93% | 11.13% | 35.99% | 24.58% |
Will probably redo the test when VC10 is out of beta. They should be able to get their std::tr1::unordered_map up to Boost’s speeds.
Another test using std::string as key, source in timemapstrings.cpp:
<std::string,int> | Insert | Lookup | Iterate | Erase |
---|---|---|---|---|
VC9 std::map SCL=1 | 100.00% | 100.00% | 100.00% | 100.00% |
VC9 stdext::hash_map SCL=1 | 48.95% | 35.26% | 361.30% | 41.52% |
VC9 std::tr1::unordered_map SCL=1 | 54.91% | 28.74% | 79.56% | 46.92% |
VC9 boost::unordered_map SCL=1 | 38.29% | 21.59% | 100.49% | 19.76% |
- | ||||
VC9 std::map SCL=0 | 98.09% | 98.45% | 92.58% | 97.40% |
VC9 stdext::hash_map SCL=0 | 43.80% | 30.80% | 356.15% | 31.72% |
VC9 std::tr1::unordered_map SCL=0 | 42.80% | 25.53% | 84.17% | 27.15% |
VC9 boost::unordered_map SCL=0 | 36.84% | 19.48% | 112.54% | 17.81% |
- | ||||
VC10 std::map SCL=1 | 51.01% | 47.37% | 103.95% | 58.40% |
VC10 std::tr1::unordered_map SCL=1 | 47.55% | 14.34% | 105.33% | 34.62% |
VC10 boost::unordered_map SCL=1 | 26.53% | 13.15% | 113.25% | 12.16% |
- | ||||
VC10 std::map SCL=0 | 50.46% | 45.61% | 93.72% | 52.53% |
VC10 std::tr1::unordered_map SCL=0 | 27.73% | 8.72% | 97.02% | 17.66% |
VC10 boost::unordered_map SCL=0 | 26.86% | 11.84% | 103.97% | 11.76% |
Paints a rather different picture.
on 20 Dec 2009 at 16:25:38 1.Mr_Dark said …
I made a small bench for myself, but I have the opposite results from what you have (std::map vs boost:unordered_map). In my bench the std::map is much faster.
Code can be found here:
http://pastebin.com/m3cd74f51
So I’d like to know what I’m doing wrong here :P
on 20 Dec 2009 at 18:48:16 2.Tino Didriksen said …
Was discussed on IRC ( irc://irc.quakenet.org/c%2b%2b ). Turns out Boost 1.38 was slower due to a serious regression when handling big containers. 1.39 and onwards ( http://www.boostpro.com/download ) are nice and smooth.