google_hash 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +61 -27
- data/Rakefile +4 -1
- data/TODO +5 -0
- data/VERSION +1 -1
- data/changelog +3 -0
- data/ext/extconf.rb +10 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/AUTHORS +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/COPYING +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/ChangeLog +47 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/INSTALL +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/Makefile.am +29 -14
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/Makefile.in +77 -42
- data/ext/sparsehash-1.8.1/NEWS +71 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/README +0 -0
- data/ext/{sparsehash-1.5.2/README.windows → sparsehash-1.8.1/README_windows.txt} +25 -25
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/TODO +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/aclocal.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/compile +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/config.guess +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/config.sub +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/configure +3690 -4560
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/configure.ac +1 -1
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/depcomp +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/dense_hash_map.html +65 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/dense_hash_set.html +65 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/designstyle.css +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/implementation.html +11 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/index.html +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/performance.html +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/sparse_hash_map.html +65 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/sparse_hash_set.html +65 -5
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/doc/sparsetable.html +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/experimental/Makefile +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/experimental/README +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/experimental/example.c +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/experimental/libchash.c +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/experimental/libchash.h +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/google-sparsehash.sln +17 -1
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/install-sh +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/acx_pthread.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/google_namespace.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/namespaces.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/stl_hash.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/stl_hash_fun.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/m4/stl_namespace.m4 +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/missing +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/mkinstalldirs +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb.sh +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/README +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/changelog +24 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/compat +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/control +1 -1
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/copyright +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/docs +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/rules +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/sparsehash.dirs +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/deb/sparsehash.install +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/rpm.sh +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/packages/rpm/rpm.spec +1 -1
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/config.h.in +3 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/config.h.include +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/dense_hash_map +43 -27
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/dense_hash_set +40 -19
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/sparse_hash_map +32 -23
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/sparse_hash_set +31 -21
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/sparsehash/densehashtable.h +481 -298
- data/ext/sparsehash-1.8.1/src/google/sparsehash/hashtable-common.h +178 -0
- data/ext/sparsehash-1.8.1/src/google/sparsehash/libc_allocator_with_realloc.h +121 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/sparsehash/sparsehashtable.h +404 -233
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/sparsetable +173 -83
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/google/type_traits.h +3 -29
- data/ext/sparsehash-1.8.1/src/hash_test_interface.h +1011 -0
- data/ext/sparsehash-1.8.1/src/hashtable_test.cc +1733 -0
- data/ext/sparsehash-1.8.1/src/libc_allocator_with_realloc_test.cc +129 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/simple_test.cc +1 -1
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/sparsetable_unittest.cc +202 -6
- data/ext/sparsehash-1.8.1/src/testutil.h +251 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/time_hash_map.cc +128 -54
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/type_traits_unittest.cc +30 -20
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/windows/config.h +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/windows/google/sparsehash/sparseconfig.h +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/windows/port.cc +0 -0
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/src/windows/port.h +0 -0
- data/ext/sparsehash-1.8.1/vsprojects/hashtable_test/hashtable_test.vcproj +197 -0
- data/ext/{sparsehash-1.5.2/vsprojects/hashtable_unittest/hashtable_unittest.vcproj → sparsehash-1.8.1/vsprojects/simple_test/simple_test.vcproj} +9 -8
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/vsprojects/sparsetable_unittest/sparsetable_unittest.vcproj +0 -2
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/vsprojects/time_hash_map/time_hash_map.vcproj +3 -2
- data/ext/{sparsehash-1.5.2 → sparsehash-1.8.1}/vsprojects/type_traits_unittest/type_traits_unittest.vcproj +0 -2
- data/ext/template/google_hash.cpp.erb +2 -1
- data/ext/template/main.cpp.erb +1 -1
- data/results.txt +6 -22
- data/spec/benchmark.rb +57 -0
- data/spec/spec.google_hash.rb +1 -8
- metadata +140 -130
- data/ext/benchmark.rb +0 -47
- data/ext/sparsehash-1.5.2/NEWS +0 -0
- data/ext/sparsehash-1.5.2/src/hashtable_unittest.cc +0 -1375
- data/ext/sparsehash-1.5.2/src/words +0 -8944
- data/types.txt +0 -18
|
@@ -32,6 +32,14 @@
|
|
|
32
32
|
//
|
|
33
33
|
// Time various hash map implementations
|
|
34
34
|
//
|
|
35
|
+
// Consider doing the following to get good numbers:
|
|
36
|
+
//
|
|
37
|
+
// 1. Run the tests on a machine with no X service. Make sure no other
|
|
38
|
+
// processes are running.
|
|
39
|
+
// 2. Minimize compiled-code differences. Compare results from the same
|
|
40
|
+
// binary, if possible, instead of comparing results from two different
|
|
41
|
+
// binaries.
|
|
42
|
+
//
|
|
35
43
|
// See PERFORMANCE for the output of one example run.
|
|
36
44
|
|
|
37
45
|
#include "config.h"
|
|
@@ -68,52 +76,84 @@ using GOOGLE_NAMESPACE::sparse_hash_map;
|
|
|
68
76
|
using GOOGLE_NAMESPACE::dense_hash_map;
|
|
69
77
|
|
|
70
78
|
|
|
79
|
+
static bool FLAGS_test_sparse_hash_map = true;
|
|
80
|
+
static bool FLAGS_test_dense_hash_map = true;
|
|
81
|
+
static bool FLAGS_test_hash_map = true;
|
|
82
|
+
static bool FLAGS_test_map = true;
|
|
83
|
+
|
|
84
|
+
static bool FLAGS_test_4_bytes = true;
|
|
85
|
+
static bool FLAGS_test_16_bytes = true;
|
|
86
|
+
static bool FLAGS_test_256_bytes = true;
|
|
87
|
+
|
|
71
88
|
static const int kDefaultIters = 10000000;
|
|
72
89
|
|
|
73
90
|
// Normally I don't like non-const references, but using them here ensures
|
|
74
91
|
// the inlined code ends up as efficient as possible.
|
|
75
92
|
|
|
76
93
|
// These are operations that are supported on some hash impls but not others
|
|
77
|
-
template<class MapType> inline void SET_DELETED_KEY(MapType
|
|
78
|
-
template<class MapType> inline void SET_EMPTY_KEY(MapType
|
|
79
|
-
template<class MapType> inline void RESIZE(MapType
|
|
94
|
+
template<class MapType> inline void SET_DELETED_KEY(MapType&, int /*key*/) {}
|
|
95
|
+
template<class MapType> inline void SET_EMPTY_KEY(MapType&, int /*key*/) {}
|
|
96
|
+
template<class MapType> inline void RESIZE(MapType&, int /*iters*/) {}
|
|
80
97
|
|
|
81
|
-
template<class K, class V, class H>
|
|
82
|
-
inline void SET_DELETED_KEY(sparse_hash_map<K,V,H>& m, int key) {
|
|
98
|
+
template<class K, class V, class H, class E, class A>
|
|
99
|
+
inline void SET_DELETED_KEY(sparse_hash_map<K,V,H,E,A>& m, int key) {
|
|
83
100
|
m.set_deleted_key(key);
|
|
84
101
|
}
|
|
85
|
-
template<class K, class V, class H>
|
|
86
|
-
inline void SET_DELETED_KEY(dense_hash_map<K,V,H>& m, int key) {
|
|
102
|
+
template<class K, class V, class H, class E, class A>
|
|
103
|
+
inline void SET_DELETED_KEY(dense_hash_map<K,V,H,E,A>& m, int key) {
|
|
87
104
|
m.set_deleted_key(key);
|
|
88
105
|
}
|
|
89
106
|
|
|
90
|
-
template<class K, class V, class H>
|
|
91
|
-
inline void SET_EMPTY_KEY(dense_hash_map<K,V,H>& m, int key) {
|
|
107
|
+
template<class K, class V, class H, class E, class A>
|
|
108
|
+
inline void SET_EMPTY_KEY(dense_hash_map<K,V,H,E,A>& m, int key) {
|
|
92
109
|
m.set_empty_key(key);
|
|
93
110
|
}
|
|
94
111
|
|
|
95
|
-
template<class K, class V, class H>
|
|
96
|
-
inline void RESIZE(sparse_hash_map<K,V,H>& m, int iters) {
|
|
112
|
+
template<class K, class V, class H, class E, class A>
|
|
113
|
+
inline void RESIZE(sparse_hash_map<K,V,H,E,A>& m, int iters) {
|
|
97
114
|
m.resize(iters);
|
|
98
115
|
}
|
|
99
|
-
template<class K, class V, class H>
|
|
100
|
-
inline void RESIZE(dense_hash_map<K,V,H>& m, int iters) {
|
|
116
|
+
template<class K, class V, class H, class E, class A>
|
|
117
|
+
inline void RESIZE(dense_hash_map<K,V,H,E,A>& m, int iters) {
|
|
101
118
|
m.resize(iters);
|
|
102
119
|
}
|
|
103
120
|
#if defined(HAVE_UNORDERED_MAP)
|
|
104
|
-
template<class K, class V, class H>
|
|
105
|
-
inline void RESIZE(HASH_NAMESPACE::unordered_map<K,V,H>& m, int iters) {
|
|
121
|
+
template<class K, class V, class H, class E, class A>
|
|
122
|
+
inline void RESIZE(HASH_NAMESPACE::unordered_map<K,V,H,E,A>& m, int iters) {
|
|
106
123
|
m.rehash(iters); // the tr1 name for resize()
|
|
107
124
|
}
|
|
125
|
+
#elif defined(_MSC_VER)
|
|
126
|
+
// MSVC/Dinkumware hash impl has fewer template args, and no resize support.
|
|
127
|
+
template<class K, class V, class H, class A>
|
|
128
|
+
inline void RESIZE(HASH_NAMESPACE::hash_map<K,V,H,A>& m, int iters) {
|
|
129
|
+
}
|
|
108
130
|
#elif defined(HAVE_HASH_MAP)
|
|
109
|
-
template<class K, class V, class H>
|
|
110
|
-
inline void RESIZE(HASH_NAMESPACE::hash_map<K,V,H>& m, int iters) {
|
|
111
|
-
#ifndef _MSC_VER /* apparently windows hash_map doesn't support resizing */
|
|
131
|
+
template<class K, class V, class H, class E, class A>
|
|
132
|
+
inline void RESIZE(HASH_NAMESPACE::hash_map<K,V,H,E,A>& m, int iters) {
|
|
112
133
|
m.resize(iters);
|
|
113
|
-
#endif // _MSC_VER
|
|
114
134
|
}
|
|
115
135
|
#endif // HAVE_HASH_MAP
|
|
116
136
|
|
|
137
|
+
// Returns the number of hashes that have been done since the last
|
|
138
|
+
// call to NumHashesSinceLastCall(). This is shared across all
|
|
139
|
+
// HashObject instances, which isn't super-OO, but avoids two issues:
|
|
140
|
+
// (1) making HashObject bigger than it ought to be (this is very
|
|
141
|
+
// important for our testing), and (2) having to pass around
|
|
142
|
+
// HashObject objects everywhere, which is annoying.
|
|
143
|
+
static int g_num_hashes;
|
|
144
|
+
static int g_num_copies;
|
|
145
|
+
|
|
146
|
+
int NumHashesSinceLastCall() {
|
|
147
|
+
int retval = g_num_hashes;
|
|
148
|
+
g_num_hashes = 0;
|
|
149
|
+
return retval;
|
|
150
|
+
}
|
|
151
|
+
int NumCopiesSinceLastCall() {
|
|
152
|
+
int retval = g_num_copies;
|
|
153
|
+
g_num_copies = 0;
|
|
154
|
+
return retval;
|
|
155
|
+
}
|
|
156
|
+
|
|
117
157
|
/*
|
|
118
158
|
* These are the objects we hash. Size is the size of the object
|
|
119
159
|
* (must be > sizeof(int). Hashsize is how many of these bytes we
|
|
@@ -126,10 +166,19 @@ template<int Size, int Hashsize> class HashObject {
|
|
|
126
166
|
HashObject(int i) : i_(i) {
|
|
127
167
|
memset(buffer_, i & 255, sizeof(buffer_)); // a "random" char
|
|
128
168
|
}
|
|
169
|
+
HashObject(const HashObject& that) {
|
|
170
|
+
operator=(that);
|
|
171
|
+
}
|
|
172
|
+
void operator=(const HashObject& that) {
|
|
173
|
+
g_num_copies++;
|
|
174
|
+
this->i_ = that.i_;
|
|
175
|
+
memcpy(this->buffer_, that.buffer_, sizeof(this->buffer_));
|
|
176
|
+
}
|
|
129
177
|
|
|
130
178
|
size_t Hash() const {
|
|
179
|
+
g_num_hashes++;
|
|
131
180
|
int hashval = i_;
|
|
132
|
-
for (
|
|
181
|
+
for (size_t i = 0; i < Hashsize - sizeof(i_); ++i) {
|
|
133
182
|
hashval += buffer_[i];
|
|
134
183
|
}
|
|
135
184
|
return SPARSEHASH_HASH<int>()(hashval); // defined in sparseconfig.h
|
|
@@ -150,8 +199,18 @@ template<> class HashObject<sizeof(int), sizeof(int)> {
|
|
|
150
199
|
typedef HashObject<sizeof(int), sizeof(int)> class_type;
|
|
151
200
|
HashObject() {}
|
|
152
201
|
HashObject(int i) : i_(i) {}
|
|
202
|
+
HashObject(const HashObject& that) {
|
|
203
|
+
operator=(that);
|
|
204
|
+
}
|
|
205
|
+
void operator=(const HashObject& that) {
|
|
206
|
+
g_num_copies++;
|
|
207
|
+
this->i_ = that.i_;
|
|
208
|
+
}
|
|
153
209
|
|
|
154
|
-
size_t Hash() const {
|
|
210
|
+
size_t Hash() const {
|
|
211
|
+
g_num_hashes++;
|
|
212
|
+
return SPARSEHASH_HASH<int>()(i_);
|
|
213
|
+
}
|
|
155
214
|
|
|
156
215
|
bool operator==(const class_type& that) const { return this->i_ == that.i_; }
|
|
157
216
|
bool operator< (const class_type& that) const { return this->i_ < that.i_; }
|
|
@@ -291,16 +350,18 @@ static size_t CurrentMemoryUsage() { return 0; }
|
|
|
291
350
|
|
|
292
351
|
static void report(char const* title, double t,
|
|
293
352
|
int iters,
|
|
294
|
-
size_t
|
|
353
|
+
size_t start_memory, size_t end_memory) {
|
|
295
354
|
// Construct heap growth report text if applicable
|
|
296
|
-
char heap[100];
|
|
297
|
-
if (
|
|
298
|
-
snprintf(heap, sizeof(heap), "%
|
|
299
|
-
|
|
300
|
-
heap[0] = '\0';
|
|
355
|
+
char heap[100] = "";
|
|
356
|
+
if (end_memory > start_memory) {
|
|
357
|
+
snprintf(heap, sizeof(heap), "%7.1f MB",
|
|
358
|
+
(end_memory - start_memory) / 1048576.0);
|
|
301
359
|
}
|
|
302
360
|
|
|
303
|
-
printf("%-20s %
|
|
361
|
+
printf("%-20s %6.1f ns (%8d hashes, %8d copies)%s\n",
|
|
362
|
+
title, (t * 1000000000.0 / iters),
|
|
363
|
+
NumHashesSinceLastCall(), NumCopiesSinceLastCall(),
|
|
364
|
+
heap);
|
|
304
365
|
fflush(stdout);
|
|
305
366
|
}
|
|
306
367
|
|
|
@@ -317,7 +378,7 @@ static void time_map_grow(int iters) {
|
|
|
317
378
|
}
|
|
318
379
|
double ut = t.UserTime();
|
|
319
380
|
const size_t finish = CurrentMemoryUsage();
|
|
320
|
-
report("map_grow", ut, iters, finish
|
|
381
|
+
report("map_grow", ut, iters, start, finish);
|
|
321
382
|
}
|
|
322
383
|
|
|
323
384
|
template<class MapType>
|
|
@@ -334,7 +395,7 @@ static void time_map_grow_predicted(int iters) {
|
|
|
334
395
|
}
|
|
335
396
|
double ut = t.UserTime();
|
|
336
397
|
const size_t finish = CurrentMemoryUsage();
|
|
337
|
-
report("map_predict/grow", ut, iters, finish
|
|
398
|
+
report("map_predict/grow", ut, iters, start, finish);
|
|
338
399
|
}
|
|
339
400
|
|
|
340
401
|
template<class MapType>
|
|
@@ -354,7 +415,7 @@ static void time_map_replace(int iters) {
|
|
|
354
415
|
}
|
|
355
416
|
double ut = t.UserTime();
|
|
356
417
|
|
|
357
|
-
report("map_replace", ut, iters, 0);
|
|
418
|
+
report("map_replace", ut, iters, 0, 0);
|
|
358
419
|
}
|
|
359
420
|
|
|
360
421
|
template<class MapType>
|
|
@@ -377,7 +438,7 @@ static void time_map_fetch(int iters) {
|
|
|
377
438
|
double ut = t.UserTime();
|
|
378
439
|
|
|
379
440
|
srand(r); // keep compiler from optimizing away r (we never call rand())
|
|
380
|
-
report("map_fetch", ut, iters, 0);
|
|
441
|
+
report("map_fetch", ut, iters, 0, 0);
|
|
381
442
|
}
|
|
382
443
|
|
|
383
444
|
template<class MapType>
|
|
@@ -396,7 +457,7 @@ static void time_map_fetch_empty(int iters) {
|
|
|
396
457
|
double ut = t.UserTime();
|
|
397
458
|
|
|
398
459
|
srand(r); // keep compiler from optimizing away r (we never call rand())
|
|
399
|
-
report("map_fetch_empty", ut, iters, 0);
|
|
460
|
+
report("map_fetch_empty", ut, iters, 0, 0);
|
|
400
461
|
}
|
|
401
462
|
|
|
402
463
|
template<class MapType>
|
|
@@ -417,7 +478,7 @@ static void time_map_remove(int iters) {
|
|
|
417
478
|
}
|
|
418
479
|
double ut = t.UserTime();
|
|
419
480
|
|
|
420
|
-
report("map_remove", ut, iters, 0);
|
|
481
|
+
report("map_remove", ut, iters, 0, 0);
|
|
421
482
|
}
|
|
422
483
|
|
|
423
484
|
template<class MapType>
|
|
@@ -438,12 +499,12 @@ static void time_map_toggle(int iters) {
|
|
|
438
499
|
double ut = t.UserTime();
|
|
439
500
|
const size_t finish = CurrentMemoryUsage();
|
|
440
501
|
|
|
441
|
-
report("map_toggle", ut, iters, finish
|
|
502
|
+
report("map_toggle", ut, iters, start, finish);
|
|
442
503
|
}
|
|
443
504
|
|
|
444
505
|
template<class MapType>
|
|
445
|
-
static void measure_map(const char* label, int iters) {
|
|
446
|
-
printf("\n%s:\n", label);
|
|
506
|
+
static void measure_map(const char* label, int obj_size, int iters) {
|
|
507
|
+
printf("\n%s (%d byte objects, %d iterations):\n", label, obj_size, iters);
|
|
447
508
|
if (1) time_map_grow<MapType>(iters);
|
|
448
509
|
if (1) time_map_grow_predicted<MapType>(iters);
|
|
449
510
|
if (1) time_map_replace<MapType>(iters);
|
|
@@ -453,19 +514,34 @@ static void measure_map(const char* label, int iters) {
|
|
|
453
514
|
if (1) time_map_toggle<MapType>(iters);
|
|
454
515
|
}
|
|
455
516
|
|
|
517
|
+
template<class ObjType>
|
|
518
|
+
static void test_all_maps(int obj_size, int iters) {
|
|
519
|
+
if (FLAGS_test_sparse_hash_map)
|
|
520
|
+
measure_map< sparse_hash_map<ObjType, int, HashFn> >("SPARSE_HASH_MAP",
|
|
521
|
+
obj_size, iters);
|
|
522
|
+
if (FLAGS_test_dense_hash_map)
|
|
523
|
+
measure_map< dense_hash_map<ObjType, int, HashFn> >("DENSE_HASH_MAP",
|
|
524
|
+
obj_size, iters);
|
|
525
|
+
#if defined(HAVE_UNORDERED_MAP)
|
|
526
|
+
if (FLAGS_test_hash_map)
|
|
527
|
+
measure_map< HASH_NAMESPACE::unordered_map<ObjType, int, HashFn> >(
|
|
528
|
+
"TR1 UNORDERED_MAP", obj_size, iters);
|
|
529
|
+
#elif defined(HAVE_HASH_MAP)
|
|
530
|
+
if (FLAGS_test_hash_map)
|
|
531
|
+
measure_map< HASH_NAMESPACE::hash_map<ObjType, int, HashFn> >(
|
|
532
|
+
"STANDARD HASH_MAP", obj_size, iters);
|
|
533
|
+
#endif
|
|
534
|
+
if (FLAGS_test_map)
|
|
535
|
+
measure_map< STL_NAMESPACE::map<ObjType, int, HashFn> >("STANDARD MAP",
|
|
536
|
+
obj_size, iters);
|
|
537
|
+
}
|
|
538
|
+
|
|
456
539
|
int main(int argc, char** argv) {
|
|
457
540
|
int iters = kDefaultIters;
|
|
458
541
|
if (argc > 1) { // first arg is # of iterations
|
|
459
542
|
iters = atoi(argv[1]);
|
|
460
543
|
}
|
|
461
544
|
|
|
462
|
-
// It would be nice to set these at run-time, but by setting them at
|
|
463
|
-
// compile-time, we allow optimizations that make it as fast to use
|
|
464
|
-
// a HashObject as it would be to use just a straight int/char buffer.
|
|
465
|
-
const int obj_size = 4;
|
|
466
|
-
const int hash_size = 4;
|
|
467
|
-
typedef HashObject<obj_size, hash_size> HashObj;
|
|
468
|
-
|
|
469
545
|
stamp_run(iters);
|
|
470
546
|
|
|
471
547
|
#ifndef HAVE_SYS_RESOURCE_H
|
|
@@ -473,16 +549,14 @@ int main(int argc, char** argv) {
|
|
|
473
549
|
" reported are wall-clock time, not user time\n");
|
|
474
550
|
#endif
|
|
475
551
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
#endif
|
|
485
|
-
measure_map< STL_NAMESPACE::map<HashObj,int,HashFn> >("STANDARD MAP", iters);
|
|
552
|
+
// It would be nice to set these at run-time, but by setting them at
|
|
553
|
+
// compile-time, we allow optimizations that make it as fast to use
|
|
554
|
+
// a HashObject as it would be to use just a straight int/char
|
|
555
|
+
// buffer. To keep memory use similar, we normalize the number of
|
|
556
|
+
// iterations based on size.
|
|
557
|
+
if (FLAGS_test_4_bytes) test_all_maps< HashObject<4,4> >(4, iters/1);
|
|
558
|
+
if (FLAGS_test_16_bytes) test_all_maps< HashObject<16,16> >(16, iters/4);
|
|
559
|
+
if (FLAGS_test_256_bytes) test_all_maps< HashObject<256,256> >(256, iters/32);
|
|
486
560
|
|
|
487
561
|
return 0;
|
|
488
562
|
}
|
|
@@ -59,7 +59,7 @@ struct A {
|
|
|
59
59
|
// A user-defined non-POD type with a trivial copy constructor.
|
|
60
60
|
class B {
|
|
61
61
|
public:
|
|
62
|
-
B(int n) : n_(n) { }
|
|
62
|
+
explicit B(int n) : n_(n) { }
|
|
63
63
|
private:
|
|
64
64
|
int n_;
|
|
65
65
|
};
|
|
@@ -69,7 +69,7 @@ class B {
|
|
|
69
69
|
// by specializing has_trivial_copy.
|
|
70
70
|
class C {
|
|
71
71
|
public:
|
|
72
|
-
C(int n) : n_(n) { }
|
|
72
|
+
explicit C(int n) : n_(n) { }
|
|
73
73
|
private:
|
|
74
74
|
int n_;
|
|
75
75
|
};
|
|
@@ -83,7 +83,7 @@ _END_GOOGLE_NAMESPACE_
|
|
|
83
83
|
// by specializing has_trivial_assign.
|
|
84
84
|
class D {
|
|
85
85
|
public:
|
|
86
|
-
D(int n) : n_(n) { }
|
|
86
|
+
explicit D(int n) : n_(n) { }
|
|
87
87
|
private:
|
|
88
88
|
int n_;
|
|
89
89
|
};
|
|
@@ -109,7 +109,7 @@ _END_GOOGLE_NAMESPACE_
|
|
|
109
109
|
// by specializing has_trivial_destructor.
|
|
110
110
|
class F {
|
|
111
111
|
public:
|
|
112
|
-
F(int n) : n_(n) { }
|
|
112
|
+
explicit F(int n) : n_(n) { }
|
|
113
113
|
private:
|
|
114
114
|
int n_;
|
|
115
115
|
};
|
|
@@ -451,20 +451,30 @@ class TypeTraitsTest {
|
|
|
451
451
|
GOOGLE_NAMESPACE::remove_cv<const volatile int>::type);
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
-
static void
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
ASSERT_TRUE((GOOGLE_NAMESPACE::
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
ASSERT_FALSE((GOOGLE_NAMESPACE::
|
|
462
|
-
|
|
463
|
-
ASSERT_TRUE((GOOGLE_NAMESPACE::
|
|
464
|
-
ASSERT_FALSE((GOOGLE_NAMESPACE::
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
454
|
+
static void TestIsSame() {
|
|
455
|
+
typedef int int32;
|
|
456
|
+
typedef long int64;
|
|
457
|
+
|
|
458
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<int32, int32>::value));
|
|
459
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<int32, int64>::value));
|
|
460
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<int64, int32>::value));
|
|
461
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<int, const int>::value));
|
|
462
|
+
|
|
463
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<void, void>::value));
|
|
464
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<void, int>::value));
|
|
465
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<int, void>::value));
|
|
466
|
+
|
|
467
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<int*, int*>::value));
|
|
468
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<void*, void*>::value));
|
|
469
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<int*, void*>::value));
|
|
470
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<void*, int*>::value));
|
|
471
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<void*, const void*>::value));
|
|
472
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<void*, void* const>::value));
|
|
473
|
+
|
|
474
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<Base*, Base*>::value));
|
|
475
|
+
ASSERT_TRUE((GOOGLE_NAMESPACE::is_same<Derived*, Derived*>::value));
|
|
476
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<Base*, Derived*>::value));
|
|
477
|
+
ASSERT_FALSE((GOOGLE_NAMESPACE::is_same<Derived*, Base*>::value));
|
|
468
478
|
}
|
|
469
479
|
|
|
470
480
|
}; // end class TypeTraitsTest
|
|
@@ -472,7 +482,7 @@ class TypeTraitsTest {
|
|
|
472
482
|
} // end anonymous namespace
|
|
473
483
|
|
|
474
484
|
|
|
475
|
-
int main(int argc
|
|
485
|
+
int main(int /*argc*/, char ** /*argv*/) {
|
|
476
486
|
TypeTraitsTest::TestIsInteger();
|
|
477
487
|
TypeTraitsTest::TestIsFloating();
|
|
478
488
|
TypeTraitsTest::TestIsReference();
|
|
@@ -486,7 +496,7 @@ int main(int argc, char **argv) {
|
|
|
486
496
|
TypeTraitsTest::TestRemoveVolatile();
|
|
487
497
|
TypeTraitsTest::TestRemoveReference();
|
|
488
498
|
TypeTraitsTest::TestRemoveCV();
|
|
489
|
-
TypeTraitsTest::
|
|
499
|
+
TypeTraitsTest::TestIsSame();
|
|
490
500
|
printf("PASS\n");
|
|
491
501
|
return 0;
|
|
492
502
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="Windows-1252"?>
|
|
2
|
+
<VisualStudioProject
|
|
3
|
+
ProjectType="Visual C++"
|
|
4
|
+
Version="7.10"
|
|
5
|
+
Name="hashtable_test"
|
|
6
|
+
ProjectGUID="{FCDB3718-F01C-4DE4-B9F5-E10F2C5C0535}"
|
|
7
|
+
Keyword="Win32Proj">
|
|
8
|
+
<Platforms>
|
|
9
|
+
<Platform
|
|
10
|
+
Name="Win32"/>
|
|
11
|
+
</Platforms>
|
|
12
|
+
<Configurations>
|
|
13
|
+
<Configuration
|
|
14
|
+
Name="Debug|Win32"
|
|
15
|
+
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
|
16
|
+
IntermediateDirectory="$(ConfigurationName)"
|
|
17
|
+
ConfigurationType="1"
|
|
18
|
+
CharacterSet="2">
|
|
19
|
+
<Tool
|
|
20
|
+
Name="VCCLCompilerTool"
|
|
21
|
+
Optimization="0"
|
|
22
|
+
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
|
23
|
+
MinimalRebuild="TRUE"
|
|
24
|
+
BasicRuntimeChecks="3"
|
|
25
|
+
RuntimeLibrary="5"
|
|
26
|
+
UsePrecompiledHeader="0"
|
|
27
|
+
WarningLevel="3"
|
|
28
|
+
DebugInformationFormat="4"/>
|
|
29
|
+
<Tool
|
|
30
|
+
Name="VCCustomBuildTool"/>
|
|
31
|
+
<Tool
|
|
32
|
+
Name="VCLinkerTool"
|
|
33
|
+
OutputFile="$(OutDir)/hashtable_test.exe"
|
|
34
|
+
LinkIncremental="2"
|
|
35
|
+
GenerateDebugInformation="TRUE"
|
|
36
|
+
ProgramDatabaseFile="$(OutDir)/hashtable_test.pdb"
|
|
37
|
+
SubSystem="1"
|
|
38
|
+
TargetMachine="1"/>
|
|
39
|
+
<Tool
|
|
40
|
+
Name="VCMIDLTool"/>
|
|
41
|
+
<Tool
|
|
42
|
+
Name="VCPostBuildEventTool"/>
|
|
43
|
+
<Tool
|
|
44
|
+
Name="VCPreBuildEventTool"/>
|
|
45
|
+
<Tool
|
|
46
|
+
Name="VCPreLinkEventTool"/>
|
|
47
|
+
<Tool
|
|
48
|
+
Name="VCResourceCompilerTool"/>
|
|
49
|
+
<Tool
|
|
50
|
+
Name="VCWebServiceProxyGeneratorTool"/>
|
|
51
|
+
<Tool
|
|
52
|
+
Name="VCXMLDataGeneratorTool"/>
|
|
53
|
+
<Tool
|
|
54
|
+
Name="VCWebDeploymentTool"/>
|
|
55
|
+
<Tool
|
|
56
|
+
Name="VCManagedWrapperGeneratorTool"/>
|
|
57
|
+
<Tool
|
|
58
|
+
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
59
|
+
</Configuration>
|
|
60
|
+
<Configuration
|
|
61
|
+
Name="Release|Win32"
|
|
62
|
+
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
|
63
|
+
IntermediateDirectory="$(ConfigurationName)"
|
|
64
|
+
ConfigurationType="1"
|
|
65
|
+
CharacterSet="2">
|
|
66
|
+
<Tool
|
|
67
|
+
Name="VCCLCompilerTool"
|
|
68
|
+
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
|
69
|
+
RuntimeLibrary="4"
|
|
70
|
+
UsePrecompiledHeader="0"
|
|
71
|
+
WarningLevel="3"
|
|
72
|
+
DebugInformationFormat="3"/>
|
|
73
|
+
<Tool
|
|
74
|
+
Name="VCCustomBuildTool"/>
|
|
75
|
+
<Tool
|
|
76
|
+
Name="VCLinkerTool"
|
|
77
|
+
OutputFile="$(OutDir)/hashtable_test.exe"
|
|
78
|
+
LinkIncremental="1"
|
|
79
|
+
GenerateDebugInformation="TRUE"
|
|
80
|
+
SubSystem="1"
|
|
81
|
+
OptimizeReferences="2"
|
|
82
|
+
EnableCOMDATFolding="2"
|
|
83
|
+
TargetMachine="1"/>
|
|
84
|
+
<Tool
|
|
85
|
+
Name="VCMIDLTool"/>
|
|
86
|
+
<Tool
|
|
87
|
+
Name="VCPostBuildEventTool"/>
|
|
88
|
+
<Tool
|
|
89
|
+
Name="VCPreBuildEventTool"/>
|
|
90
|
+
<Tool
|
|
91
|
+
Name="VCPreLinkEventTool"/>
|
|
92
|
+
<Tool
|
|
93
|
+
Name="VCResourceCompilerTool"/>
|
|
94
|
+
<Tool
|
|
95
|
+
Name="VCWebServiceProxyGeneratorTool"/>
|
|
96
|
+
<Tool
|
|
97
|
+
Name="VCXMLDataGeneratorTool"/>
|
|
98
|
+
<Tool
|
|
99
|
+
Name="VCWebDeploymentTool"/>
|
|
100
|
+
<Tool
|
|
101
|
+
Name="VCManagedWrapperGeneratorTool"/>
|
|
102
|
+
<Tool
|
|
103
|
+
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
|
104
|
+
</Configuration>
|
|
105
|
+
</Configurations>
|
|
106
|
+
<References>
|
|
107
|
+
</References>
|
|
108
|
+
<Files>
|
|
109
|
+
<Filter
|
|
110
|
+
Name="Source Files"
|
|
111
|
+
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
112
|
+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
|
113
|
+
<File
|
|
114
|
+
RelativePath="..\..\src\hashtable_test.cc">
|
|
115
|
+
<FileConfiguration
|
|
116
|
+
Name="Debug|Win32">
|
|
117
|
+
<Tool
|
|
118
|
+
Name="VCCLCompilerTool"
|
|
119
|
+
AdditionalIncludeDirectories="..\..\src\windows; ..\..\src"/>
|
|
120
|
+
</FileConfiguration>
|
|
121
|
+
<FileConfiguration
|
|
122
|
+
Name="Release|Win32">
|
|
123
|
+
<Tool
|
|
124
|
+
Name="VCCLCompilerTool"
|
|
125
|
+
AdditionalIncludeDirectories="..\..\src\windows; ..\..\src"/>
|
|
126
|
+
</FileConfiguration>
|
|
127
|
+
</File>
|
|
128
|
+
<File
|
|
129
|
+
RelativePath="..\..\src\windows\port.cc">
|
|
130
|
+
<FileConfiguration
|
|
131
|
+
Name="Debug|Win32">
|
|
132
|
+
<Tool
|
|
133
|
+
Name="VCCLCompilerTool"
|
|
134
|
+
AdditionalIncludeDirectories="..\..\src\windows; ..\..\src"/>
|
|
135
|
+
</FileConfiguration>
|
|
136
|
+
<FileConfiguration
|
|
137
|
+
Name="Release|Win32">
|
|
138
|
+
<Tool
|
|
139
|
+
Name="VCCLCompilerTool"
|
|
140
|
+
AdditionalIncludeDirectories="..\..\src\windows; ..\..\src"/>
|
|
141
|
+
</FileConfiguration>
|
|
142
|
+
</File>
|
|
143
|
+
</Filter>
|
|
144
|
+
<Filter
|
|
145
|
+
Name="Header Files"
|
|
146
|
+
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
|
147
|
+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
|
148
|
+
<File
|
|
149
|
+
RelativePath="..\..\src\windows\config.h">
|
|
150
|
+
</File>
|
|
151
|
+
<File
|
|
152
|
+
RelativePath="..\..\src\google\dense_hash_map">
|
|
153
|
+
</File>
|
|
154
|
+
<File
|
|
155
|
+
RelativePath="..\..\src\google\dense_hash_set">
|
|
156
|
+
</File>
|
|
157
|
+
<File
|
|
158
|
+
RelativePath="..\..\src\google\sparsehash\densehashtable.h">
|
|
159
|
+
</File>
|
|
160
|
+
<File
|
|
161
|
+
RelativePath="..\..\src\windows\port.h">
|
|
162
|
+
</File>
|
|
163
|
+
<File
|
|
164
|
+
RelativePath="..\..\src\google\sparse_hash_map">
|
|
165
|
+
</File>
|
|
166
|
+
<File
|
|
167
|
+
RelativePath="..\..\src\google\sparse_hash_set">
|
|
168
|
+
</File>
|
|
169
|
+
<File
|
|
170
|
+
RelativePath="..\..\src\windows\google\sparsehash\sparseconfig.h">
|
|
171
|
+
</File>
|
|
172
|
+
<File
|
|
173
|
+
RelativePath="..\..\src\google\sparsehash\sparsehashtable.h">
|
|
174
|
+
</File>
|
|
175
|
+
<File
|
|
176
|
+
RelativePath="..\..\src\google\sparsehash\hashtable-common.h">
|
|
177
|
+
</File>
|
|
178
|
+
<File
|
|
179
|
+
RelativePath="..\..\src\google\sparsetable">
|
|
180
|
+
</File>
|
|
181
|
+
<File
|
|
182
|
+
RelativePath="..\..\src\google\sparsehash\libc_allocator_with_realloc.h">
|
|
183
|
+
</File>
|
|
184
|
+
<File
|
|
185
|
+
RelativePath="..\..\src\google\type_traits.h">
|
|
186
|
+
</File>
|
|
187
|
+
<File
|
|
188
|
+
RelativePath="..\..\src\testutil.h">
|
|
189
|
+
</File>
|
|
190
|
+
<File
|
|
191
|
+
RelativePath="..\..\src\hash_test_interface.h">
|
|
192
|
+
</File>
|
|
193
|
+
</Filter>
|
|
194
|
+
</Files>
|
|
195
|
+
<Globals>
|
|
196
|
+
</Globals>
|
|
197
|
+
</VisualStudioProject>
|