Guest User

Map perf test

a guest
May 24th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1.  
  2. static const char* words[] =
  3. {
  4.     "fug",
  5.     "fugacities",
  6.     "fugacity",
  7.     "fugal",
  8.     "fugally",
  9.     "fugato",
  10.     "fugatos",
  11.     "fugged",
  12.     "fuggier",
  13.     "fuggiest",
  14.     "fugging",
  15.     "fuggy",
  16.     "fugio",
  17.     "fugios",
  18.     "fugitive",
  19.     "fugitively",
  20.     "fugitiveness",
  21.     "fugitives",
  22.     "fugle",
  23.     "fugled",
  24.     "fugleman",
  25.     "fuglemen",
  26.     "fugles",
  27.     "fugling",
  28.     "fugs",
  29.     "fugu",
  30.     "fugue",
  31.     "fugued",
  32.     "fugues",
  33.     "fuguing",
  34.     "fuguist",
  35.     "fuguists",
  36.     "fugus",
  37.     "fuhrer",
  38.     "fuhrers",
  39.     "fuji",
  40.     "fug",
  41.     "fugacities",
  42.     "fugacity",
  43.     "fugal",
  44.     "fugally",
  45.     "fugato",
  46.     "fugatos",
  47.     "fugged",
  48.     "fuggier",
  49.     "fuggiest",
  50.     "fugging",
  51.     "fuggy",
  52.     "fugio",
  53.     "fugios",
  54.     "fugitive",
  55.     "fugitively",
  56.     "fugitiveness",
  57.     "fugitives",
  58.     "fugle",
  59.     "fugled",
  60.     "fugleman",
  61.     "fuglemen",
  62.     "fugles",
  63.     "fugling",
  64.     "fugs",
  65.     "fugu",
  66.     "fugue",
  67.     "fugued",
  68.     "fugues",
  69.     "fuguing",
  70.     "fuguist",
  71.     "fuguists",
  72.     "fugus",
  73.     "fuhrer",
  74.     "fuhrers",
  75.     "fuji",
  76. };
  77.  
  78. template<class String, class Map> void TestMap( Map& map, Timer* timer, int test_size, const char* desc )
  79. {
  80.     ReadWriteBarrier();
  81.     double begin = timer->Elapsed();
  82.     ReadWriteBarrier();
  83.     for( int i=0; i!=test_size; ++i )
  84.     {
  85.         int word_index = i % eiArraySize(words);
  86.         map[String(words[word_index])] = i;
  87.     }
  88.     ReadWriteBarrier();
  89.     double middle = timer->Elapsed();
  90.     ReadWriteBarrier();
  91.     int sum = 0;
  92.     for( int i=0; i!=test_size; ++i )
  93.     {
  94.         int word_index = i % eiArraySize(words);
  95.         sum += map[String(words[word_index])];
  96.     }
  97.     ReadWriteBarrier();
  98.     double end = timer->Elapsed();
  99.     ReadWriteBarrier();
  100.     printf("%s size %d, Write: %f ms, Read: %f ms. Result = %d\n", desc, test_size, float(middle - begin)*1000.0f, float(end - middle)*1000.0f, sum);
  101. }
  102.  
  103.  
  104. ..................
  105.  
  106.  
  107.         for(int itrSample = 0; itrSample < 5; itrSample++)
  108.         {
  109.             int test_size = (int)pow(10,itrSample+1);
  110.             { std::map<          std::string, int> map;                 TestMap<std::string>( map, timer, test_size, "std::map            " ); }
  111.             { std::unordered_map<std::string, int> map(test_size);      TestMap<std::string>( map, timer, test_size, "std::unordered_map  " ); }
  112.             { VectorMap<         std::string, int> map(test_size);      TestMap<std::string>( map, timer, test_size, "VectorMap           " ); }
  113.             { rde::hash_map<     std::string, int> map(test_size);      TestMap<std::string>( map, timer, test_size, "rde::hash_map       " ); }
  114.             { HashTable<               void*, int> map( a, test_size ); TestMap<      void*>( map, timer, test_size, "eight::CheatTable   " ); }
  115.             { HashTable<         const char*, int> map( a, test_size ); TestMap<const char*>( map, timer, test_size, "eight::HashTable1   " ); }
  116.             { HashTable<              String, int> map( a, test_size ); TestMap<     String>( map, timer, test_size, "eight::HashTable2   " ); }
  117.             { MpmcHashTable<          String, int> map( a, test_size ); TestMap<     String>( map, timer, test_size, "eight::MpmcHashTable" ); }
  118.             printf("\n");
  119.         }
Advertisement
Add Comment
Please, Sign In to add comment