forked from jl2922/fhash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.cc
38 lines (34 loc) · 943 Bytes
/
benchmark.cc
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
#include <boost/functional/hash.hpp>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <unordered_map>
#include <vector>
#define N_INTS 2
#define N_KEYS 20000000
void benchmark() {
typedef std::vector<int> KeyType;
const std::clock_t start = std::clock();
std::unordered_map<KeyType, double, boost::hash<KeyType>> h;
h.reserve(N_KEYS * 2);
KeyType key(N_INTS);
for (int i = 1; i <= N_KEYS; i++) {
for (int j = 1; j <= N_INTS; j++) {
key[j - 1] = i + j;
}
h[key] = i * 0.5;
}
const std::clock_t finish = std::clock();
printf("Time insert: %.3g s\n",
static_cast<double>(finish - start) / CLOCKS_PER_SEC);
h.clear();
}
int main() {
typedef std::vector<int> KeyType;
const std::clock_t start = std::clock();
benchmark();
const std::clock_t finish = std::clock();
printf("Time finish: %.3g s\n",
static_cast<double>(finish - start) / CLOCKS_PER_SEC);
return 0;
}