Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static const char* words[] =
- {
- "fug",
- "fugacities",
- "fugacity",
- "fugal",
- "fugally",
- "fugato",
- "fugatos",
- "fugged",
- "fuggier",
- "fuggiest",
- "fugging",
- "fuggy",
- "fugio",
- "fugios",
- "fugitive",
- "fugitively",
- "fugitiveness",
- "fugitives",
- "fugle",
- "fugled",
- "fugleman",
- "fuglemen",
- "fugles",
- "fugling",
- "fugs",
- "fugu",
- "fugue",
- "fugued",
- "fugues",
- "fuguing",
- "fuguist",
- "fuguists",
- "fugus",
- "fuhrer",
- "fuhrers",
- "fuji",
- "fug",
- "fugacities",
- "fugacity",
- "fugal",
- "fugally",
- "fugato",
- "fugatos",
- "fugged",
- "fuggier",
- "fuggiest",
- "fugging",
- "fuggy",
- "fugio",
- "fugios",
- "fugitive",
- "fugitively",
- "fugitiveness",
- "fugitives",
- "fugle",
- "fugled",
- "fugleman",
- "fuglemen",
- "fugles",
- "fugling",
- "fugs",
- "fugu",
- "fugue",
- "fugued",
- "fugues",
- "fuguing",
- "fuguist",
- "fuguists",
- "fugus",
- "fuhrer",
- "fuhrers",
- "fuji",
- };
- template<class String, class Map, class Clear> void TestMap( Map& map, Timer* timer, int test_size, const char* desc, Clear& clear )
- {
- int sum = 0;
- double a=0, b=0, c=0;
- for( int i=0; i!=10; ++i )
- {
- ReadWriteBarrier();
- double begin = timer->Elapsed();
- ReadWriteBarrier();
- for( int i=0; i!=test_size; ++i )
- {
- int word_index = i % eiArraySize(words);
- map[String(words[word_index])] = i;
- }
- ReadWriteBarrier();
- double middle = timer->Elapsed();
- ReadWriteBarrier();
- for( int i=0; i!=test_size; ++i )
- {
- int word_index = i % eiArraySize(words);
- sum += map[String(words[word_index])];
- }
- ReadWriteBarrier();
- double end = timer->Elapsed();
- ReadWriteBarrier();
- a += middle - begin;
- b += end - middle;
- c += end - begin;
- clear();
- }
- printf("%s size %d, Write: %f ms, Read: %f ms. Total: %f. Result = %d\n", desc, test_size, a*1000, b*1000, c*1000, sum);
- }
- ..................
- for(int itrSample = 0; itrSample < 5; itrSample++)
- {
- int test_size = (int)pow(10,itrSample+1);
- { std::map< std::string, int> map; TestMap<std::string>( map, timer, test_size, "std::map ", [&](){map.clear();} ); }
- { std::unordered_map<std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "std::unordered_map ", [&](){map.clear();} ); }
- { VectorMap< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "VectorMap ", [&](){map.clear();} ); }
- { rde::hash_map< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "rde::hash_map ", [&](){map.clear();} ); }
- { HashTable< void*, int> map( a, test_size ); TestMap< void*>( map, timer, test_size, "eight::CheatTable ", [&](){map.~ HashTable(); new(&map) HashTable< void*, int>( a, test_size );} ); }
- { HashTable< const char*, int> map( a, test_size ); TestMap<const char*>( map, timer, test_size, "eight::HashTable1 ", [&](){map.~ HashTable(); new(&map) HashTable<const char*, int>( a, test_size );} ); }
- { HashTable< String, int> map( a, test_size ); TestMap< String>( map, timer, test_size, "eight::HashTable2 ", [&](){map.~ HashTable(); new(&map) HashTable< String, int>( a, test_size );} ); }
- { MpmcHashTable< String, int> map( a, test_size ); TestMap< String>( map, timer, test_size, "eight::MpmcHashTable", [&](){map.~MpmcHashTable(); new(&map) MpmcHashTable< String, int>( a, test_size );} ); }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement