I currently have some code where I am using a vector of pair<string,string>. This is used to store some data from XML parsing and as such, the process is quite slow in places. In terms of trying to speed up the entire process I was wondering if there would be any performance advantage in switching from vector<pair<string,string> > to std::map<string,string> ? I could code it up and run a profiler, but I thought I would see if I could get an answer that suggests some obvious performance gain first. I am not required to do any sorting, I simply add items to the vector, then at a later stage iterate over the contents and do some processing – I have no need for sorting or anything of that nature. I am guessing that perhaps I would not get any performance gain, but I have never actually used a std::map before so I don’t know without asking or coding it all up.
I currently have some code where I am using a vector of pair<string,string> .
Share
No. If (as you say) you are simply iterating over the collection, you will see a small (probably not measurable) performance decrease by using a
std::map.Maps are for accessing a value by its key. If you never do this, map is a bad choice for a container.