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>InsertLookupIterateErase
VC9 std::map SCL=1100.00%100.00%100.00%100.00%
VC9 stdext::hash_map SCL=1112.00%127.38%528.65%130.07%
VC9 std::tr1::unordered_map SCL=1111.63%128.45%534.87%157.24%
VC9 boost::unordered_map SCL=155.11%9.13%38.77%28.82%
-
VC9 std::map SCL=0100.11%107.19%93.81%98.85%
VC9 stdext::hash_map SCL=088.96%70.56%546.17%101.48%
VC9 std::tr1::unordered_map SCL=089.33%61.26%543.59%98.22%
VC9 boost::unordered_map SCL=052.30%8.38%32.44%27.84%
-
VC10 std::map SCL=1106.64%114.93%94.85%107.75%
VC10 std::tr1::unordered_map SCL=1213.29%216.05%51.13%169.92%
VC10 boost::unordered_map SCL=154.80%11.02%38.12%25.14%
-
VC10 std::map SCL=098.01%95.26%90.87%88.27%
VC10 std::tr1::unordered_map SCL=0121.01%70.59%28.32%81.65%
VC10 boost::unordered_map SCL=052.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>InsertLookupIterateErase
VC9 std::map SCL=1100.00%100.00%100.00%100.00%
VC9 stdext::hash_map SCL=148.95%35.26%361.30%41.52%
VC9 std::tr1::unordered_map SCL=154.91%28.74%79.56%46.92%
VC9 boost::unordered_map SCL=138.29%21.59%100.49%19.76%
-
VC9 std::map SCL=098.09%98.45%92.58%97.40%
VC9 stdext::hash_map SCL=043.80%30.80%356.15%31.72%
VC9 std::tr1::unordered_map SCL=042.80%25.53%84.17%27.15%
VC9 boost::unordered_map SCL=036.84%19.48%112.54%17.81%
-
VC10 std::map SCL=151.01%47.37%103.95%58.40%
VC10 std::tr1::unordered_map SCL=147.55%14.34%105.33%34.62%
VC10 boost::unordered_map SCL=126.53%13.15%113.25%12.16%
-
VC10 std::map SCL=050.46%45.61%93.72%52.53%
VC10 std::tr1::unordered_map SCL=027.73%8.72%97.02%17.66%
VC10 boost::unordered_map SCL=026.86%11.84%103.97%11.76%

Paints a rather different picture.

2 Responses to “C++ Map Speeds, MSVC++ Edition”

  1. 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

  2. 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.

Subscribe to the comments through RSS Feed

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image