Created
April 20, 2023 14:24
-
-
Save zhouyuan/9d518e832551eec3efd56fb3ad890deb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <boost/container/map.hpp> | |
#include <chrono> | |
#include <iostream> | |
#include <map> | |
#include <random> | |
#include <unordered_map> | |
#include <vector> | |
#include "parallel_hashmap/btree.h" | |
#include "parallel_hashmap/phmap.h" | |
#include "absl/container/btree_map.h" | |
struct keyRow { | |
int a = 0; | |
int b = 0; | |
}; | |
int main() { | |
std::random_device rnd_device; | |
// Specify the engine and distribution. | |
std::mt19937 mersenne_engine{rnd_device()}; // Generates random integers | |
std::uniform_int_distribution<int> dist{1, 128}; | |
auto gen = [&dist, &mersenne_engine]() { return dist(mersenne_engine); }; | |
std::vector<int> ltab(100'000); | |
generate(begin(ltab), end(ltab), gen); | |
std::vector<int> rtab(1000'000); | |
generate(begin(rtab), end(rtab), gen); | |
// std::vector<int32_t> ltab = {1, 2, 3}; | |
// std::vector<int32_t> rtab = {2, 3, 3}; | |
// std::multimap<int32_t, keyRow> hashMap; | |
boost::container::multimap<int32_t, keyRow> hashMap; | |
// phmap::btree_multimap<int32_t, keyRow> hashMap; | |
// absl::btree_multimap<int32_t, keyRow> hashMap; | |
auto start = std::chrono::steady_clock::now(); | |
for (auto lkey : ltab) { | |
hashMap.emplace(std::make_pair(lkey, keyRow())); | |
} | |
auto end = std::chrono::steady_clock::now(); | |
std::chrono::duration<double> elapsed_seconds = end - start; | |
std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n"; | |
for (auto rkey : rtab) { | |
auto range = hashMap.equal_range(rkey); | |
for (auto i = range.first; i != range.second; ++i) { | |
// std::cout << "joined " << i->first << (i->second).a << std::endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment