-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconstruct_search_cpp.cpp
More file actions
51 lines (45 loc) · 1.16 KB
/
construct_search_cpp.cpp
File metadata and controls
51 lines (45 loc) · 1.16 KB
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
#include <iostream>
#include <fstream>
#include <chrono>
#include <ctime>
#include <google/dense_hash_map>
#include <string.h>
using namespace std;
using namespace google;
struct eqstr
{
bool operator()(const char *s1, const char *s2) const
{
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
}
};
int main(int argc, char **argv){
ifstream in(argv[1]);
string input_string;
char foo[] = "foo";
chrono::time_point<chrono::system_clock> start, end;
chrono::duration<double> t1, t2;
dense_hash_map<const char *, const char *, hash<const char *>, eqstr> d;
unsigned int lc=0, miss=0;
d.set_empty_key(NULL);
while(in >> input_string){
start = chrono::system_clock::now();
d[input_string.c_str()] = foo;
end = chrono::system_clock::now();
t1 += end-start;
lc++;
}
in.close();
in.open(argv[1]);
while(in >> input_string){
start = chrono::system_clock::now();
if (d.find(input_string.c_str()) == d.end())
miss++;
end = chrono::system_clock::now();
t2 += end-start;
}
in.close();
cout << "C-Dense-Hash\t" << argv[1] << "\t" << lc <<
"\t" << t1.count() << "\t" << t2.count() << endl;
return 0;
}