This is a follow up question to Char* vs String Speed in C++. I have declared the following variables:
std::vector<std::string> siteNames_;
std::vector<unsigned int> ids_;
std::vector<std::string> names_;
I call this function tens of thousands of times and is a major bottleneck. Is there a more efficient way to compare strings? The answer must be cross-platform compatible.
unsigned int converter::initilizeSiteId(unsigned int siteNumber){
unsigned int siteId = 0;
for (unsigned int i = 0; i < ids_.size(); i ++){
if (siteNames_[siteNumber].compare(names_[i]) == 0){
siteId = ids_[i];
break; // Once found, will stop searching and break out of for loop
}
}
if (siteId == 0)
std::cerr << "Could not find ID for site number " << siteNumber << std::endl;
return siteId;
}