SHOW:
|
|
- or go back to the newest paste.
1 | static const char* words[] = | |
2 | { | |
3 | "fug", | |
4 | "fugacities", | |
5 | "fugacity", | |
6 | "fugal", | |
7 | "fugally", | |
8 | "fugato", | |
9 | "fugatos", | |
10 | "fugged", | |
11 | "fuggier", | |
12 | "fuggiest", | |
13 | "fugging", | |
14 | "fuggy", | |
15 | "fugio", | |
16 | "fugios", | |
17 | "fugitive", | |
18 | "fugitively", | |
19 | "fugitiveness", | |
20 | "fugitives", | |
21 | "fugle", | |
22 | "fugled", | |
23 | "fugleman", | |
24 | "fuglemen", | |
25 | "fugles", | |
26 | "fugling", | |
27 | "fugs", | |
28 | "fugu", | |
29 | "fugue", | |
30 | "fugued", | |
31 | "fugues", | |
32 | "fuguing", | |
33 | "fuguist", | |
34 | "fuguists", | |
35 | "fugus", | |
36 | "fuhrer", | |
37 | "fuhrers", | |
38 | "fuji", | |
39 | "fug", | |
40 | "fugacities", | |
41 | "fugacity", | |
42 | "fugal", | |
43 | "fugally", | |
44 | "fugato", | |
45 | "fugatos", | |
46 | "fugged", | |
47 | "fuggier", | |
48 | "fuggiest", | |
49 | "fugging", | |
50 | "fuggy", | |
51 | "fugio", | |
52 | "fugios", | |
53 | "fugitive", | |
54 | "fugitively", | |
55 | "fugitiveness", | |
56 | "fugitives", | |
57 | "fugle", | |
58 | "fugled", | |
59 | "fugleman", | |
60 | "fuglemen", | |
61 | "fugles", | |
62 | "fugling", | |
63 | "fugs", | |
64 | "fugu", | |
65 | "fugue", | |
66 | "fugued", | |
67 | "fugues", | |
68 | "fuguing", | |
69 | "fuguist", | |
70 | "fuguists", | |
71 | "fugus", | |
72 | "fuhrer", | |
73 | "fuhrers", | |
74 | "fuji", | |
75 | }; | |
76 | ||
77 | template<class String, class Map, class Clear> void TestMap( Map& map, Timer* timer, int test_size, const char* desc, Clear& clear ) | |
78 | - | template<class String, class Map> void TestMap( Map& map, Timer* timer, int test_size, const char* desc ) |
78 | + | |
79 | int sum = 0; | |
80 | - | ReadWriteBarrier(); |
80 | + | double a=0, b=0, c=0; |
81 | - | double begin = timer->Elapsed(); |
81 | + | for( int i=0; i!=10; ++i ) |
82 | - | ReadWriteBarrier(); |
82 | + | |
83 | - | for( int i=0; i!=test_size; ++i ) |
83 | + | ReadWriteBarrier(); |
84 | double begin = timer->Elapsed(); | |
85 | - | int word_index = i % eiArraySize(words); |
85 | + | ReadWriteBarrier(); |
86 | - | map[String(words[word_index])] = i; |
86 | + | for( int i=0; i!=test_size; ++i ) |
87 | { | |
88 | - | ReadWriteBarrier(); |
88 | + | int word_index = i % eiArraySize(words); |
89 | - | double middle = timer->Elapsed(); |
89 | + | map[String(words[word_index])] = i; |
90 | - | ReadWriteBarrier(); |
90 | + | } |
91 | ReadWriteBarrier(); | |
92 | - | for( int i=0; i!=test_size; ++i ) |
92 | + | double middle = timer->Elapsed(); |
93 | ReadWriteBarrier(); | |
94 | - | int word_index = i % eiArraySize(words); |
94 | + | for( int i=0; i!=test_size; ++i ) |
95 | - | sum += map[String(words[word_index])]; |
95 | + | |
96 | int word_index = i % eiArraySize(words); | |
97 | - | ReadWriteBarrier(); |
97 | + | sum += map[String(words[word_index])]; |
98 | - | double end = timer->Elapsed(); |
98 | + | } |
99 | - | ReadWriteBarrier(); |
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); |
100 | + | double end = timer->Elapsed(); |
101 | ReadWriteBarrier(); | |
102 | ||
103 | a += middle - begin; | |
104 | b += end - middle; | |
105 | c += end - begin; | |
106 | ||
107 | clear(); | |
108 | } | |
109 | 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); | |
110 | - | { std::map< std::string, int> map; TestMap<std::string>( map, timer, test_size, "std::map " ); } |
110 | + | |
111 | - | { std::unordered_map<std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "std::unordered_map " ); } |
111 | + | |
112 | - | { VectorMap< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "VectorMap " ); } |
112 | + | |
113 | - | { rde::hash_map< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "rde::hash_map " ); } |
113 | + | |
114 | - | { HashTable< void*, int> map( a, test_size ); TestMap< void*>( map, timer, test_size, "eight::CheatTable " ); } |
114 | + | |
115 | - | { HashTable< const char*, int> map( a, test_size ); TestMap<const char*>( map, timer, test_size, "eight::HashTable1 " ); } |
115 | + | |
116 | - | { HashTable< String, int> map( a, test_size ); TestMap< String>( map, timer, test_size, "eight::HashTable2 " ); } |
116 | + | |
117 | - | { MpmcHashTable< String, int> map( a, test_size ); TestMap< String>( map, timer, test_size, "eight::MpmcHashTable" ); } |
117 | + | |
118 | int test_size = (int)pow(10,itrSample+1); | |
119 | { std::map< std::string, int> map; TestMap<std::string>( map, timer, test_size, "std::map ", [&](){map.clear();} ); } | |
120 | { std::unordered_map<std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "std::unordered_map ", [&](){map.clear();} ); } | |
121 | { VectorMap< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "VectorMap ", [&](){map.clear();} ); } | |
122 | { rde::hash_map< std::string, int> map(test_size); TestMap<std::string>( map, timer, test_size, "rde::hash_map ", [&](){map.clear();} ); } | |
123 | { 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 );} ); } | |
124 | { 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 );} ); } | |
125 | { 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 );} ); } | |
126 | { 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 );} ); } | |
127 | ||
128 | printf("\n"); | |
129 | } |