diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-11-28 17:52:49 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-11-28 17:52:49 +0000 |
commit | 190fa93b41aaca71a9f7fc84a3856a79fc40444d (patch) | |
tree | a0dd217e4abbd5907294305a2b55bd6ae70bd826 /vespalib | |
parent | 02d4f862b3111d9b715bdb4b8ebe536ab5880887 (diff) |
Also test with hash_map
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/stllike/lookup_benchmark.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/vespalib/src/tests/stllike/lookup_benchmark.cpp b/vespalib/src/tests/stllike/lookup_benchmark.cpp index 98aff9cd4ce..4f65bebe560 100644 --- a/vespalib/src/tests/stllike/lookup_benchmark.cpp +++ b/vespalib/src/tests/stllike/lookup_benchmark.cpp @@ -8,6 +8,7 @@ #include <vector> #include <algorithm> #include <vespa/vespalib/stllike/hash_set.hpp> +#include <vespa/vespalib/stllike/hash_map.hpp> template <typename S> void fill(S & s, size_t count) @@ -17,6 +18,14 @@ void fill(S & s, size_t count) } } +template <typename M> +void fillM(M & m, size_t count) +{ + for(size_t i(0); i < count; i++) { + m[i] = i; + } +} + template <typename S> size_t lookup_bench(S & s, size_t count, size_t rep) { @@ -43,6 +52,13 @@ size_t bench(S & set, size_t sz, size_t numLookups) return lookup_bench(set, sz, numLookups/sz); } +template <typename M> +size_t benchM(M & map, size_t sz, size_t numLookups) +{ + fillM(map, sz); + return lookup_bench(map, sz, numLookups/sz); +} + size_t benchMap(size_t sz, size_t numLookups) { std::set<uint32_t> set; @@ -57,16 +73,28 @@ size_t benchHashStl(size_t sz, size_t numLookups) size_t benchHashVespaLib(size_t sz, size_t numLookups) { - vespalib::hash_set<uint32_t> set; + vespalib::hash_set<uint32_t> set(3*sz); return bench(set, sz, numLookups); } size_t benchHashVespaLib2(size_t sz, size_t numLookups) { - vespalib::hash_set<uint32_t, vespalib::hash<uint32_t>, std::equal_to<uint32_t>, vespalib::hashtable_base::and_modulator > set; + vespalib::hash_set<uint32_t, vespalib::hash<uint32_t>, std::equal_to<uint32_t>, vespalib::hashtable_base::and_modulator > set(3*sz); return bench(set, sz, numLookups); } +size_t benchHashMapVespaLib(size_t sz, size_t numLookups) +{ + vespalib::hash_map<uint32_t, uint32_t> set(3*sz); + return benchM(set, sz, numLookups); +} + +size_t benchHashMapVespaLib2(size_t sz, size_t numLookups) +{ + vespalib::hash_map<uint32_t, uint32_t, vespalib::hash<uint32_t>, std::equal_to<uint32_t>, vespalib::hashtable_base::and_modulator > set(3*sz); + return benchM(set, sz, numLookups); +} + int main(int argc, char *argv[]) { size_t count(1000); @@ -86,12 +114,16 @@ int main(int argc, char *argv[]) description['h'] = "std::hash_set"; description['g'] = "vespalib::hash_set"; description['G'] = "vespalib::hash_set with simple and modulator."; + description['k'] = "vespalib::hash_map"; + description['K'] = "vespalib::hash_map with simple and modulator."; size_t found(0); switch (type) { case 'm': found = benchMap(count, rep); break; case 'h': found = benchHashStl(count, rep); break; case 'g': found = benchHashVespaLib(count, rep); break; case 'G': found = benchHashVespaLib2(count, rep); break; + case 'k': found = benchHashMapVespaLib(count, rep); break; + case 'K': found = benchHashMapVespaLib2(count, rep); break; default: printf("'m' = %s\n", description[type]); printf("'h' = %s\n", description[type]); |