|
18 | 18 | #include "libcuckoo/cuckoohash_map.hh"
|
19 | 19 |
|
20 | 20 | #include "codegen/util/oa_hash_table.h"
|
| 21 | +#include "codegen/util/hash_table.h" |
21 | 22 | #include "common/timer.h"
|
| 23 | +#include "type/ephemeral_pool.h" |
22 | 24 |
|
23 | 25 | namespace peloton {
|
24 | 26 | namespace test {
|
@@ -47,10 +49,10 @@ class OAHashTableTest : public PelotonTest {
|
47 | 49 |
|
48 | 50 | OAHashTableTest() : ht_(sizeof(Key), sizeof(Value)) {}
|
49 | 51 |
|
50 |
| - static uint32_t Hash(const Key &k) { |
| 52 | + static uint64_t Hash(const Key &k) { |
51 | 53 | static constexpr uint32_t seed = 12345;
|
52 |
| - auto h1 = MurmurHash3_x86_32(&k.k1, sizeof(uint32_t), seed); |
53 |
| - auto h2 = MurmurHash3_x86_32(&k.k2, sizeof(uint32_t), seed); |
| 54 | + uint64_t h1 = MurmurHash3_x86_32(&k.k1, sizeof(uint32_t), seed); |
| 55 | + uint64_t h2 = MurmurHash3_x86_32(&k.k2, sizeof(uint32_t), seed); |
54 | 56 | return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
|
55 | 57 | }
|
56 | 58 |
|
@@ -147,6 +149,7 @@ TEST_F(OAHashTableTest, MicroBenchmark) {
|
147 | 149 | }
|
148 | 150 |
|
149 | 151 | double avg_oaht_insert = 0.0, avg_oaht_probe = 0.0;
|
| 152 | + double avg_lazyht_insert = 0.0, avg_lazyht_probe = 0.0; |
150 | 153 | double avg_map_insert = 0.0, avg_map_probe = 0.0;
|
151 | 154 | double avg_cuckoo_insert = 0.0, avg_cuckoo_probe = 0.0;
|
152 | 155 |
|
@@ -186,6 +189,42 @@ TEST_F(OAHashTableTest, MicroBenchmark) {
|
186 | 189 | }
|
187 | 190 | }
|
188 | 191 |
|
| 192 | + // First, bench ours ... |
| 193 | + { |
| 194 | + for (uint32_t b = 0; b < num_runs; b++) { |
| 195 | + ::peloton::type::EphemeralPool pool; |
| 196 | + codegen::util::HashTable ht(pool, sizeof(Key), sizeof(Value)); |
| 197 | + |
| 198 | + Timer<std::ratio<1, 1000>> timer; |
| 199 | + timer.Start(); |
| 200 | + |
| 201 | + // Start Insert |
| 202 | + for (uint32_t i = 0; i < num_keys; i++) { |
| 203 | + ht.TypedInsertLazy(Hash(keys[i]), keys[i], v); |
| 204 | + } |
| 205 | + ht.BuildLazy(); |
| 206 | + // End Insert |
| 207 | + |
| 208 | + timer.Stop(); |
| 209 | + avg_lazyht_insert += timer.GetDuration(); |
| 210 | + |
| 211 | + timer.Reset(); |
| 212 | + timer.Start(); |
| 213 | + |
| 214 | + // Start Probe |
| 215 | + std::vector<Key> shuffled = keys; |
| 216 | + std::random_shuffle(shuffled.begin(), shuffled.end()); |
| 217 | + for (uint32_t i = 0; i < num_keys; i++) { |
| 218 | + Value probe_val; |
| 219 | + EXPECT_TRUE(ht.TypedProbe(Hash(shuffled[i]), shuffled[i], probe_val)); |
| 220 | + } |
| 221 | + // End Probe |
| 222 | + |
| 223 | + timer.Stop(); |
| 224 | + avg_lazyht_probe += timer.GetDuration(); |
| 225 | + } |
| 226 | + } |
| 227 | + |
189 | 228 | // Next, unordered_map ...
|
190 | 229 | {
|
191 | 230 | struct Hasher {
|
@@ -262,6 +301,9 @@ TEST_F(OAHashTableTest, MicroBenchmark) {
|
262 | 301 | LOG_INFO("OA_HT insert: %.2lf, probe: %.2lf",
|
263 | 302 | avg_oaht_insert / (double)num_runs,
|
264 | 303 | avg_oaht_probe / (double)num_runs);
|
| 304 | + LOG_INFO("Lazy HT insert: %.2lf, probe: %.2lf", |
| 305 | + avg_lazyht_insert / (double)num_runs, |
| 306 | + avg_lazyht_probe / (double)num_runs); |
265 | 307 | LOG_INFO("std::unordered_map insert: %.2lf, probe: %.2lf",
|
266 | 308 | avg_map_insert / (double)num_runs, avg_map_probe / (double)num_runs);
|
267 | 309 | LOG_INFO("Cuckoo insert: %.2lf, probe: %.2lf",
|
|
0 commit comments