-
Notifications
You must be signed in to change notification settings - Fork 5
/
bench.cc
63 lines (53 loc) · 1.34 KB
/
bench.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
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <map>
#include <vector>
#include <assert.h>
#ifdef _MSC_VER
#include <hash_map>
#else
#include <tr1/unordered_map>
using namespace std::tr1;
#define hash_map unordered_map
#endif
using namespace std;
int main(int argc, char* argv[]) {
map<int, int> m;
hash_map<int, int> um;
vector<int> v;
static const int TOT = 1000000;
const int N = atoi(argv[1]);
for (int i = 0; i < N; i++) {
v.push_back(rand());
//v.push_back(i);
//v.push_back(0);
}
{
clock_t cl = clock();
for (int t = 0; t < TOT/N; t++) {
for (int i = 0; i < v.size(); i++) {
um.insert(make_pair(v[i], i));
}
for (int i = 0; i < v.size(); i++) {
um.erase(v[i]);
}
}
assert(m.empty());
printf("%.3f\n", ((double)clock() - cl) / CLOCKS_PER_SEC);
}
{
clock_t cl = clock();
for (int t = 0; t < TOT/N; t++) {
for (int i = 0; i < v.size(); i++) {
m.insert(make_pair(v[i], i));
}
for (int i = 0; i < v.size(); i++) {
m.erase(v[i]);
}
}
assert(m.empty());
printf("%.3f\n", ((double)clock() - cl) / CLOCKS_PER_SEC);
}
}