#include #include #include #include #include #include #include #include #include #include #include using namespace std ; typedef chrono::time_point SystemTime ; template tuple hash_test(vector &keys) { int count(0); int insertTime(0), fetchTime(0) ; { HashType hash ; { SystemTime start(chrono::system_clock::now()); for(KeyType &t : keys) hash [t] = 1; SystemTime end(chrono::system_clock::now()); insertTime = chrono::duration_cast(end-start).count(); } { SystemTime start(chrono::system_clock::now()); for(KeyType &t : keys) count += hash [t]; SystemTime end(chrono::system_clock::now()); fetchTime = chrono::duration_cast(end-start).count(); } } //count is used to ensure that the compiler optimisations don't remove the hashing operations return tuple (insertTime, fetchTime, count); } template void maptest(const char *context, vector &keys) { auto uMapTimes = hash_test, Key>(keys); auto oMapTimes = hash_test, Key>(keys); cout<(uMapTimes)<(uMapTimes)<(oMapTimes)<(oMapTimes)< integerKeys(KeyCount); for(int i=0; i randomStrings(KeyCount) ; for(int i=0; i wordKeys ; ifstream input("wordlist.txt"); assert(input.good()); while(!input.eof()) { string s ; input >> s ; wordKeys.push_back(s); } input.close(); maptest(" ** Integer Keys ** ", integerKeys); maptest(" ** Random String Keys ** ", randomStrings); maptest(" ** Real Words Keys ** ", wordKeys); return 0 ; }