I wanted to use a HashMap to get better performance for data lookup. However the following test shows HashMap running 4x slower than std::map.
- Code: Select all
std::map<std::string, int> stdMap;
Poco::HashMap<std::string, int> pocoMap;
std::vector<std::string> keys;
//populate maps
Poco::Random randGenerator;
for (int i = 0; i < 30000; i++)
{
std::stringstream ss;
for (int j = 0; j < 20; j++) //generate 20 character key string
{
int charIndex = (int)(randGenerator.nextDouble() * 25.0);
ss << (char)('a' + charIndex);
}
stdMap[ss.str()] = i;
pocoMap[ss.str()] = i;
keys.push_back(ss.str());
}
//run performance test
Poco::Stopwatch sw;
sw.start();
for (unsigned int i = 0; i < 30000; i++)
{
std::map<std::string, int>::const_iterator it = stdMap.find(keys[i]);
}
cout << "stdMap: " << sw.elapsed() << endl;
sw.reset();
sw.start();
for (unsigned int i = 0; i < 30000; i++)
{
Poco::HashMap<std::string, int>::ConstIterator it = pocoMap.find(keys[i]);
}
cout << "pocoMap: " << sw.elapsed() << endl;
As you can see I'm using default hash implementation for strings - I don't know how it's implemented in Poco.





