Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- #include <vector>
- #include <unordered_map>
- #include <map>
- #include <chrono>
- #include <boost/random/mersenne_twister.hpp>
- #include <boost/random/uniform_int_distribution.hpp>
- #include <google/dense_hash_map>
- #include <google/sparsehash/libc_allocator_with_realloc.h>
- #include "concurrent_map.h"
- static constexpr int SIZE = 10000000;
- void bench() {
- boost::random::mt19937 rng;
- boost::random::uniform_int_distribution<> dist(std::numeric_limits<uint64_t>::min(), std::numeric_limits<uint64_t>::max());
- std::vector<uint64_t> vec(SIZE);
- for (int i = 0; i < SIZE; ++i) {
- uint64_t val = 0;
- while (val == 0) {
- val = dist(rng);
- }
- vec[i] = val;
- }
- std:unordered_map<int, long double> map;
- //google::dense_hash_map<int, long double> map;
- //map.set_empty_key(0);
- auto begin = std::chrono::high_resolution_clock::now();
- for (int i = 0; i < SIZE; ++i) {
- map[vec[i]] = 0.0;
- }
- auto end = std::chrono::high_resolution_clock::now();
- auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
- std::cout << "inserts: " << elapsed.count() << std::endl;
- std::random_shuffle(vec.begin(), vec.end());
- begin = std::chrono::high_resolution_clock::now();
- long double val;
- for (int i = 0; i < SIZE; ++i) {
- val = map[vec[i]];
- }
- end = std::chrono::high_resolution_clock::now();
- elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
- std::cout << "get: " << elapsed.count() << std::endl;
- }
- int main()
- {
- bench();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement