C++ 09 Jul 2009 23:43:35

C++ Map Speeds, GNU g++ Edition

(There is also an MSVC++ Edition of these performance tests, and a newer std::set comparison.)

While testing whether anything would break by switching to std::tr1::unordered_map for CG-3, I noticed it ran a consistent 15% faster. So, for my own curiousity, I threw together this little speed test: timemap.cpp with cycle.h.

Should be compiled with GCC g++ of at least version 4.3 to have TR1, and with -O2 or higher; -O will not optimize the hash maps sufficiently.

Now, that is obviously a naive test. Maps of integer to integer is a trivial case, but it is also a case I use often in CG-3 so I figured it would suit fine for a test. Results are as follows, with std::map set as reference 100% and lower is better.


And the corresponding test for std::string as key, again std::map set to 100% and lower is better:


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