-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
81 lines (66 loc) · 2.38 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <random>
#include <chrono>
#include "DynPerfectHash.hpp"
#define DO_NOT_OPTIMIZE(value) asm volatile("" : : "r,m"(value) : "memory")
int main() {
std::random_device rd;
std::mt19937_64 gen(4);
std::uniform_int_distribution<uint64_t> dis;
size_t size = (1<<24)*0.84;
size_t queries = 1e8;
std::vector<std::tuple<uint64_t , uint64_t>> pairs;
pairs.reserve(size);
for (size_t i = 0; i < size; ++i) {
pairs.emplace_back(dis(gen), dis(gen));
}
std::cout<< "create dyn"<<std::endl;
DynPerfectHashTable<uint64_t,uint64_t> table(pairs);
std::cout<< "check perfect"<<std::endl;
std::vector<bool> taken;
taken.resize(size*4);
for(auto& p :pairs) {
uint64_t pos=table.query(std::get<0>(p));
if(taken[pos]) {
exit(1);
}
taken[pos]=true;
}
std::cout<< "check out"<<std::endl;
for(auto& p :pairs) {
if(table.get(std::get<0>(p)) != std::get<1>(p)) {
exit(1);
}
}
/*std::cout<< "create std"<<std::endl;
std::unordered_map<uint64_t, uint64_t > map;
for(auto& p :pairs) {
map[std::get<0>(p)]=std::get<1>(p);
}*/
std::cout<< "prepare query"<<std::endl;
std::vector<uint64_t> queryInputs;
queryInputs.reserve(queries);
for (int i = 0; i < queries; ++i) {
uint64_t pos = dis(gen) % size;
queryInputs.push_back(std::get<0>(pairs[pos]));
}
std::chrono::steady_clock::time_point begin;
std::chrono::steady_clock::time_point end;
uint64_t sum=0;
/*
std::cout<< "measure std"<<std::endl;
begin = std::chrono::steady_clock::now();
for (int i = 0; i < queries; ++i) { DO_NOT_OPTIMIZE(map[queryInputs[i]]); }
end = std::chrono::steady_clock::now();
std::cout << "Time difference = " << (std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count() / double(queries)) << "[ns]" << std::endl;
*/
std::cout<< "measure dyn"<<std::endl;
begin = std::chrono::steady_clock::now();
for (int j = 0; j < 25; ++j) {
for (int i = 0; i < queries; ++i) { DO_NOT_OPTIMIZE(table.query(queryInputs[i])); }
}
end = std::chrono::steady_clock::now();
std::cout << "Time difference = " << (std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count() / double(queries*25)) << "[ns]" << std::endl;
DO_NOT_OPTIMIZE(sum);
return 0;
}