I wanted to map data with pointer as the key. What container should I have chosen, map or unordered_map? There are multiple questions on stackoverflow for this topic but none of them covers the performance aspect when we need to iterate over all the key-value pairs.
std::map<classKey* , classData*> myMap;
std::unordered_map<classKey* , classData*> myUnorderedMap;
for (auto & iter : myMap) { //loop1
display(iter.second);
}
for (auto & iter : myUnorderedMap) { //loop2
display(iter.second);
}
loop1 vs loop2 which one gives better performance.
Aucun commentaire:
Enregistrer un commentaire