In this following test, which I compiled on apple clang with -O3, I have taken steps to ensure that the test is fair, such as:
call a sink function with the result of each search through a vtable, to prevent the optimiser inlining away entire searches!
run tests on 3 different kinds of maps, containing the same data, in the same order in parallel. This means that if one test starts to 'get ahead', it starts entering cache-miss territory for the search set (see code). This means that no one test gets an unfair advantage of encountering a 'hot' cache.
parameterise the key size (and therefore complexity)
parameterised the map size
tested three different kinds of maps (containing the same data) - an unordered_map, a map and a sorted vector of key/value pairs.
checked the assembler output to ensure that the optimiser has not been able to optimise away entire chunks of logic due to dead code analysis.
Here is the code:
#include
#include
#include
#include
#include
#include
Results:
ordered time: 972711
unordered time: 335821
flat map time: 559768
As you can see, the unordered_map convincingly beats the map and the sorted pair vector. The vector of pairs has twice as fast as the map solution. This is interesting as lower_bound and map::at have almost equivalent complexity.
TL;DR
in this test, the unordered map is approximately 3 times as fast (for lookups) as an ordered map, and a sorted vector convincingly beats a map.
I was actually shocked at how much faster it is.